STL之LIST使用

// List.cpp : 定義控制檯應用程序的入口點。
//


#include "stdafx.h"
#include "stdlib.h"
#define NULL 0
#define TYPE struct stu
#define LEN sizeof(struct stu)
struct stu{
int num;
int age;
struct stu *next;
};




TYPE  *creat(int n)
{
struct stu *head,*pf,*pb;
int i;
for(i=0;i<n;++i)
{
pb=(TYPE *)malloc(LEN);
printf("input Number and Age \n");
scanf("%d\n%d",&pb->num,&pb->age);
//printf("input Number and Age \n");
if(i==0)
{
pf=head=pb;

}
else 
{
pf->next=pb;
}
pb->next = NULL;
pf=pb;
if(i==4)
{


for(int n=0;n<=i;n++)
{
if(n==4)
{
pb=(TYPE *)malloc(LEN);
printf("插入鏈表");
scanf("%d\n%d\n",&pb->num,&pb->age);
pf=head->next;
pb->next=pf;
head = pb;
}
//pb=(TYPE *)malloc(LEN);
printf("input\n");
if(n==0)
pb=head;
else
pb=pb->next;
printf("%d\n%d\n",pb->age,pb->num);


}


}
}


return(head);


}






int _tmain(int argc, _TCHAR* argv[])
{
creat(5);
return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章