我用的是人民邮电出版社的数据结构。这篇是对以前学习链表的总结。先写一个输入输出的代码:
#include<stdio.h>
#include<stdlib.h> //这个就是()malloc(size())的头文件
typedef struct node
{
int info;
struct node *next;
}node;
node* creatnode() //这里要注意*我也不知道干什么的,指针我也没学好,感觉以后代码变多了自然就会了,懒得深究,但别忘了加上
{
node *head=(node *)malloc(sizeof(node)); //申请空间,像线性表一类的可以不申请,但是这个不申请会报错,我也不知道为毛。
head->info=0;
node *tail=head;
for(int i=0; i<4; i++)
{
node *stl=(node *)malloc(sizeof(node)); //用一个申请一个。
scanf("%d",&stl->info);
stl->next=NULL;
tail->next=stl; //tail是中间值,和冒泡排序差不多。
tail=stl;
}
return head;
}
node* display(node *head)
{
node *stl=head->next; //要把head略过去。
while(stl!=NULL)
{
printf("%d\n",stl->info);
stl=stl->next;
}
return head;
}
int main()
{
node *head=(node *)malloc(sizeof(node));
head=creatnode();
display(head);
return 0;
}
把这个复制粘贴可以直接用。里面我也有很多不清楚的,以后代码编的多了自然就好了~~~~~~~~
感觉会了这个其他的一堆就都ok了。