qsr10250030  
saturn
日历
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456
统计
  • 随笔 - 15
  • 文章 - 0
  • 评论 - 6
  • 引用 - 0

导航

常用链接

留言簿(2)

随笔档案(15)

金属网

我的编程

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
#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<<"请输入要插入的人名:\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;
                                            }
 
 
posted on 2007-01-12 19:03 快乐蝴蝶飞 阅读(265) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


 
Copyright © 快乐蝴蝶飞 Powered by: 博客园 模板提供:沪江博客