STL之LIST使用

来源:互联网 发布:淘宝推广八戒晨昊网络 编辑:程序博客网 时间:2024/05/17 10:55
// 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;
}
0 0
原创粉丝点击