#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
//结构体定义
struct Student
{
//业务数据
const char name[32];
int id;
int classID;
//下面的字段纯粹是为了建立链表用
struct TstField
{
struct Student *sle_next;
} MyField;
};
//链表结构体定义
SLIST_HEAD(myStuList,Student);
struct myStuList stuHead;
static void* NewStudent()
{
struct Student *stu;
stu= malloc(sizeof(struct Student));
return stu;
}
void main()
{
int k;
int i;
struct Student *stu;
struct Student *stu1;
struct Student *stu2;
struct Student *stu3;
SLIST_INIT(&stuHead);
stu=NewStudent();
if(NULL==stu){return;}
stu->classID=0;
stu->id=100;
strcpy(stu->name,"jiayp");
SLIST_INSERT_HEAD(&stuHead,stu,MyField);
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
printf("\r\n");
for(i=1;i<3;i++)
{
stu1=NewStudent();
if(NULL==stu1){return;}
stu1->classID=i;
stu1->id=100;
sprintf(stu1->name,"wang%d",i);
SLIST_INSERT_AFTER(stu,stu1,MyField);
}
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
printf("\r\n");
SLIST_REMOVE_HEAD(&stuHead,MyField);
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
}
#include <stdlib.h>
#include "queue.h"
//结构体定义
struct Student
{
//业务数据
const char name[32];
int id;
int classID;
//下面的字段纯粹是为了建立链表用
struct TstField
{
struct Student *sle_next;
} MyField;
};
//链表结构体定义
SLIST_HEAD(myStuList,Student);
struct myStuList stuHead;
static void* NewStudent()
{
struct Student *stu;
stu= malloc(sizeof(struct Student));
return stu;
}
void main()
{
int k;
int i;
struct Student *stu;
struct Student *stu1;
struct Student *stu2;
struct Student *stu3;
SLIST_INIT(&stuHead);
stu=NewStudent();
if(NULL==stu){return;}
stu->classID=0;
stu->id=100;
strcpy(stu->name,"jiayp");
SLIST_INSERT_HEAD(&stuHead,stu,MyField);
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
printf("\r\n");
for(i=1;i<3;i++)
{
stu1=NewStudent();
if(NULL==stu1){return;}
stu1->classID=i;
stu1->id=100;
sprintf(stu1->name,"wang%d",i);
SLIST_INSERT_AFTER(stu,stu1,MyField);
}
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
printf("\r\n");
SLIST_REMOVE_HEAD(&stuHead,MyField);
SLIST_FOREACH(stu3,&stuHead,MyField)
{
printf(stu3->name);
printf("\r\n");
}
}