#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node* next;
}Node;
//单链表的初始化
Node* initList()
{
Node* head = (Node*)malloc(sizeof(Node));
head->data = 0;
head->next = NULL;
return head;
}
//头插法
int inserthead(Node* L, int e)
{
Node* p = (Node*)malloc(sizeof(Node));
p->data = e;
p->next = L->next;
L->next = p;
}
//单链表的遍历
void listNode(Node* L)
{
Node* p = (Node*)malloc(sizeof(Node));
p = L->next;
while (p != NULL)
{
printf("%d ", p->data);
p = p->next;
}
printf("\n");
}
int main()
{
Node* list = initList();
inserthead(list, 10);
inserthead(list, 20);
inserthead(list, 30);
listNode(list);
return 0;
}
01-20
3552

09-16
1万+

03-28
6052

12-10
641
