最近重新写链表代码时,发现又是不会写。今天重新整理下简单链表的思路。
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
typedef struct list
{
int node;
struct list *next;
}num;
{
int node;
struct list *next;
}num;
int main()
{
int i,number = 0;
num *h,*c,*p;
h = NULL;
p = NULL;
printf("input your num:");
scanf("%d",&number);
for(i = 0;i<number;i++)
{
c = (num*)malloc(sizeof(num));
if (h == NULL)
h = c;
else
p->next = c;
c->next = NULL;
printf("input the %d number:",i+1);
scanf("%d",&c->node);
//printf("the number is %d",c->node);
p = c;
}
if(h == NULL)