// ConsoleApplication7.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include"iostream" using namespace std; typedef int data; typedef struct link_node { data info; link_node *next; }node; node *init() { node *head=(node *)malloc(sizeof(node)); head->next = NULL; head->info = 0; return head; } int print(node *head) { node *p = head; while (p->next!=NULL) { p = p->next; cout << p->info << endl; } return 0; } node *insert_head(node *head, data x) { node *q = (node *)malloc(sizeof(node)); q->info = x; q->next = head->next; head->next = q; return head; } int _tmain(int argc, _TCHAR* argv[]) { node *head = init(); for (int i = 0; i < 6;i++) head = insert_head(head, i+99); print(head); return 0; }
后面还有循环单链表、双链表,然而没想出来这两个链表用在何处,所以就不写了!
原文地址:https://www.cnblogs.com/butchert/p/12078398.html
时间: 2024-11-04 11:24:04