该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
// linklist.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
typedef int ElemType;
typedef int status;
typedef struct LNode{
int stu_num;
string name;
char sex;
struct LNode *next;
}LNode,*LinkList;
status Init_L(LinkList &L,int n,int *stu_num,string *name){
LNode *p,*q;
int count=0;
L=(LinkList)malloc(sizeof(LNode));
q=L;
for(int i=0;i
p=(LinkList)malloc(sizeof(LNode));
p->stu_num=stu_num[i];
p->name=name[i];
printf("系统已为你随机生成学号:%s,姓名:%s。\n请输入性别(*男*or*女*):",p->stu_num,p->name);
scanf_s("%c",&p->sex);
printf("\n");
q->next=p;//让头节点的next记住P的位置;
q=p;//然后P的位置就变成了q,第二次循环的时候就是
}
q->next=NULL;
return OK;
}
status Printf_L(LinkList &L,int n,int *stu_num,string *name){
LNode *p,*q;
q=L;
int count=0;
L=(LinkList)malloc(sizeof(LNode));
for(int i=0;i
p=(LinkList)malloc(sizeof(LNode));
p=q->next;
printf("第%d位同学的信息:%d,%d,%d",i+1,p->stu_num,p->name,p->sex);
q=p;
}
return OK;
}
int main( void){
LinkList L;
int why;
int stu_num[]={7,18};//,22,25,30,33,37};
string name[]={"陈为汉","郑定锻"};//,"曾易辉","陈旭锋","林栋","魏小东","张路强"};
int n=sizeof(stu_num)/sizeof(int);
Init_L(L,n,stu_num,name);
Printf_L(L,n,stu_num,name);
return OK;
}