//输入学生信息---------------------------------------------------------
PStudents CreateStudent()
{
CreateSmWindow("输入",20,12,20,15,0,15);
PStudents pStu = new Students;
MoveCursorTo(22,14);
printf("输入学生信息:\n");
MoveCursorTo(22,15);
printf("学号:");
MoveCursorTo(28,15);
scanf("%s",pStu->cStuId);
MoveCursorTo(22,16);
printf("姓名:");
MoveCursorTo(28,16);
scanf("%s",pStu->cStuName);
MoveCursorTo(22,17);
printf("年龄:");
MoveCursorTo(28,17);
scanf("%d",&pStu->nAge);
MoveCursorTo(22,18);
printf("性别:");
MoveCursorTo(28,18);
scanf("%s",&pStu->cStuSex);
MoveCursorTo(22,19);
printf("JAVA分数:");
MoveCursorTo(32,19);
scanf("%lf",&pStu->dbJava);
MoveCursorTo(22,20);
printf("C++分数:");
MoveCursorTo(31,20);
scanf("%lf",&pStu->dbC);
MoveCursorTo(22,21);
printf("english分数:");
MoveCursorTo(35,21);
scanf("%lf",&pStu->dbEnglish);
return pStu;
}
//输入添加学生-------------------------------------------
void CreateList(LNode& pHead)
{
LNode pNode = new Node;
pNode->Stu = CreateStudent();
pNode->pNext = NULL;
if(NULL == pHead)
{
pHead = pNode;
}
else
{
LNode pTmp = pHead;
while(NULL != pTmp->pNext)
{
pTmp = pTmp->pNext;
}
pTmp->pNext = pNode;
}
return;
}
//遍历把N个学生信息显示出来----------------------------------------------
void Transert(LNode pHead)
{
LNode pTmp = pHead;
while(NULL != pTmp)
{
ShowStudent(pTmp->Stu);
pTmp = pTmp->pNext;
}
return;
}
//删除一个节点学生的信息----------------------------------------------
void DeleteNode(LNode& pHead, char* Name)
{
if(NULL != pHead)
{
if(strcmp(pHead->Stu->cStuName,Name) == 0)
{
LNode pNode = pHead;//如果是头节点用另外一个变量记住这个节点的下一个地址,就可以删除了
pHead = pHead->pNext;
delete pNode->Stu;
delete pNode;
pNode = NULL;
}
else //如果是中间和尾部接点的时候
{
LNode pPre = pHead;
LNode pTail = pHead->pNext;
while((NULL != pTail) && (strcmp(pTail->Stu->cStuName,Name) != 0))//一直循环到相匹配的接点
{
pPre = pTail;
pTail = pTail->pNext;
}
if(NULL != pTail)
{
pPre->pNext = pTail->pNext;
delete pTail->Stu;
delete pTail;
pTail = NULL;
}
}
}
return;
}
//先贴几个简单功能你先看看,代码是我3年前写的。不怎么经典,封装比较烂,但功能还是能实现。过几天我会把完整的代码给你。