程序设计
#include <stdio.h>
#include <string.h>
#include <malloc.h>
typedef struct _STU //定义一个学生结构体变量
{
int num;
char name[20];
char sex;
int age;
_STU(int n, char nm[],char sx,int ag)
{
num = n;
strcpy(name, nm);
sex = sx;
age = ag;
}
}STU;
typedef struct _NODE
{
STU s;
struct _NODE *next;
}NODE ,*PNODE;
void InsertHead(PNODE *ppHead, STU s) //插入头结点
{
PNODE PNew = (PNODE)malloc(sizeof(NODE));
PNew->s= s;
PNew->next = *ppHead;
*ppHead = PNew;
}
void InsertTail(PNODE *ppHead,STU s) //链表的尾插法
{
if (NULL == *ppHead)
{
InsertHead(ppHead, s); //若头结点为空,则头插一个结点
}
else
{
PNODE pos = *ppHead;
while (pos->next != NULL