在看了一下队列的时候顺便温习了一下链表,之前对C语言的链表只是有过接触,因为当时感觉难就没学习,现在回头看了下,只得学习单向链表,根据网上百度的自己模仿的写了一个链表的代码,如下:
#include<stdio.h>
#include<stdlib.h>struct node
{
int data;
struct node *next;
};
int main()
{
struct node *p,*tail,*head;
tail = p = head = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
while(p->data != 0)
{
head = p;
p = (struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
head->next = p;
}
p->next = NULL;
p = tail;
printf("shuchu:");
while(p->next != NULL)
{
printf("%d\t",p->data);
p = p->next;
}
printf("%d\t",p->data);
return 0;
}
其中代码没有问题,可以直接运行,本人是刚接触不久,有什么问题直接留言交流,欢迎转发。