标题:关于链表的一道题
只看楼主
xph4444
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-10-21
 问题点数:0 回复次数:0 
关于链表的一道题
#include<iostream>
using namespace std;
int m,n;
struct node
{ int num;
char name[10];
int age;
int salary;
}a;
struct list
{ node data;
list *next;
};
list *head;
list *input(node)
{ list *s,*p,*q;
s=new list;
s->data=a;s->next=NULL;
if (head==NULL)
{head=s;return head;}
if (head->data.num>s->data.num)
{s->next=head;head=s;
return (head);
}
for(q=head,p=head->next;p;q=p,p=p->next)
if (p->data.num>s->data.num)
{s->next=p;q->next=s;
return ( head ) ;
}
q->next=s;
return (head);
}
void showlist(const list *)
{cout<<"Now the sorted information are:\n";
while(head)
{cout<<head->data.num<<head->data.name<<head->data.age<<head->data.salary<<endl;head=head->next;}
return;
}
void find_people(const list *head)
{ list *h=new list;
cin>>h->data.num;
int flag=0;
{while(head)
if(head->data.num==h->data.num) {cout<<head->data.num<<" "<<head->data.name<<" "<<head->data.age<<" "<<head->data.salary<<endl;return;}
head=head->next;
}
cout<<"can't find!"<<endl;
return;
}

void main()
{ cout<<"Input the total:";
cin>>m;
head=NULL;
cout<<"Input the information of the "<<m<<" students."<<endl;
cin>>a.num>>a.name>>a.age>>a.salary;
head=NULL;
while(a.num!=0)
{head=input(a);cin>>a.num>>a.name>>a.age>>a.salary;}
showlist(head);
cout<<"Please input the num of the person you want:\n";
find_people(head);
}
这道题要求输入若干员工信息,按照编号由小到大遍历输出
输入一个编号输出指定员工的信息
是不是在定义void find_people(const list *head) 时出错了?
搜索更多相关主题的帖子: 链表 
2008-10-26 09:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-240639-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.106868 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved