快捷导航

数据结构萌新的问题

数据结构老师在给我们复习C语言时布置了一个实验,内容如图,由于没有学习过这一内容,故向大家请教。

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

这是个链表
#includestructStudentNode{charname[10];intrank;intscore;StudentNode*pNext;StudentNode():name(""),rank(0),score(0),pNext(nullptr){}};structStudentLinkList{StudentNode*pHead;StudentLinkList():pHead(newStudentNode){}~StudentLinkList(){StudentNode*node=pHead;while(node!=nullptr){StudentNode*tmp=node->pNext;deletenode;node=tmp;}}voidcreateLinkList(intn){printf("creatinglinklistwith%dnodes\n",n);StudentNode*node=pHead;StudentNode*tmp;for(autoi=1;iname,&(tmp->rank),&(tmp->score));node->pNext=tmp;node=tmp;tmp=nullptr;}printf("linklistcreated\n\n");}voidshowLinkList(){printf("displayallelementsoflinklist\n>>");StudentNode*node=pHead;while(node->pNext!=nullptr){printf("|%s|%d|%d|-->",node->pNext->name,node->pNext->rank,node->pNext->score);node=node->pNext;}printf("null\n\n");}};intmain(){StudentLinkListlinkList;linkList.createLinkList(3);linkList.showLinkList();}
C:\Users\xxx\CLionProjects\Test\cmake-build-debug\Test.exe
creating linklist with 3 nodes
>> input 1st node's infos: name, rank, score: WANG 1 65
>> input 2st node's infos: name, rank, score: ZHANG 2 98
>> input 3st node's infos: name, rank, score: LI 3 85
linklist created


display all elements of linklist
>> | WANG | 1 | 65 | --> | ZHANG | 2 | 98 | --> | LI | 3 | 85 | --> null




Process finished with exit code 0


回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP