qsr10250030 |
|
|||
saturn |
日歷
統(tǒng)計(jì)
導(dǎo)航常用鏈接留言簿(2)隨筆檔案(15)金屬網(wǎng)我的編程
搜索最新評(píng)論
閱讀排行榜評(píng)論排行榜 |
#include<iostream>
#include<conio.h> #include<fstream> #include<sstream> #define null 0 using namespace std; int main(){ struct stu{ long num; string name; stu *next;}; struct stu *head,*h1,*h2; h1=h2=new stu; cin>>h1->num>>h1->name; head=null; int n=0; while(h1->num!=0){ ?? n=n+1; ?? if(n==1)head=h1; ?? else h2->next=h1; ?? h2=h1; ?? h1=new stu; ?? cin>>h1->num>>h1->name;?? ? } ? h2->next=null; ?h1=head; ? if(head!=null) ?? do{cout<<h1->num<<" "<<h1->name<<endl; ?? h1=h1->next; ?? }while(h1!=null); ? cout<<"請(qǐng)輸入要插入的人名:\n" ; ? stu *s; ? s=new stu; ? cin>>s->num>>s->name; ? h1=head; ? if(head==null){head=s;s->next=null;} ? else ? { ????? while((s->num>h1->num)&&(h1->next!=null)){ ??????????????????????????????????????????????? h2=h1; h1=h1->next;} ???? if(s->num<=h1->num){ ???????????????????????? if(head==h1){head=s;s->next=h1;} ???????????????????????? else {h2->next=s;s->next=h1;}} ???? else{h1->next=s;s->next=null;} ???? } ? h1=head; ? if(head!=null) ?? do{cout<<h1->num<<" "<<h1->name<<endl; ?? h1=h1->next; ?? }while(h1!=null); ??????????????????????????????????????????? getch(); ??????????????????????????????????????????? return 0; ??????????????????????????????????????????? } ? ?
|
![]() |
|
Copyright © 快樂蝴蝶飛 | Powered by: 博客園 模板提供:滬江博客 |