链表-结构体list
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
int num
struct node *next;
}Node;
typedef struct _list{
Node *head;
Node *tail;
}List;
void print(List *pList);
void add(List *pList,int number,int count);
int main()
{
int number;
List list;
int count=0;
list.head=list.tail=NULL;
do
{
scanf("%d",&number);
count++;
if(number!=-1)
{
add(&list,number,count);
}
}while(number!=-1);
print(&list);
}
void add(List *pList,int number,int count)
{
Node *p=(Node*)malloc(sizeof(Node));
p->num=number;
p->next=NULL;
Node *last=pList->head;
if(count==1)
{
pList->tail=p;
pList->head=p;
}
else
{
pList->tail->next=p;
pList->tail=p;
}
}
void print(List *pList)
{
Node *p;
for(p=pList->head;p;p=p->next)
{
printf("%d\t",p->num);
}
free(p);
}