注册 登录
编程论坛 C++教室

建立一个10结点的单向链表

Lucky01 发布于 2015-12-05 15:57, 802 次点击
建立一个10结点的单向链表,每个结点包括:学号、姓名、性别、年龄。对其进行排序,采用插入排序法,按学号从小到大排序。
7 回复
#2
hellovfp2015-12-05 21:13
有什么问题?
#3
TonyDeng2015-12-05 21:30
以下是引用hellovfp在2015-12-5 21:13:37的发言:

有什么问题?

问题就是谁来做功课?
#4
hellovfp2015-12-05 22:26
以下是引用TonyDeng在2015-12-5 21:30:10的发言:


问题就是谁来做功课?


貌似有这个趋势,哈哈
#5
Lucky012015-12-06 00:02
对呀,链表我不会,会的教教我,用C++来编程
#6
hellovfp2015-12-06 00:45
c++里有标准链表库,根本不需要你写,排序也是,不需要你写。
#7
yangfrancis2015-12-06 19:26
//建立结点类
class Node
{
public:
    char name[9];
    Node*next;
}
//新产生一个元素
Node*stu1;stu1=new Node;
stu1->name="abc";stu1->next=NULL;
//将一个结点地址由前一结点的next指针保存,形成链
stu2->name="ef";stu2->next=NULL;
stu1->next=stu2;
//这是大概思路,其他自己慢慢啃吧
#8
Lucky012015-12-07 22:26
#include<iostream.h>
struct Student         //结构声明
{  //定义结构变量
    int id;
    char name[20];
    char sex[10];
    int age;
    Student *next;
};
Student *head;
Student *a[10];
Student *Create()//创建链表结构
{
    Student *s,*p;
    s=new Student;
    cin>>s->id>>s->name>>s->sex>>s->age;
    head=NULL;
    while(s->id!=0)
    {
        if(head==NULL)
            head=s;
        else
            p->next=s;
        p=s;
        s=new Student;
        cin>>s->id>>s->name>>s->sex>>s->age;
    }
    p->next=NULL;
    delete s;
    return head;
}
void paixu(head)//插入法排序
{
    Student *st,*pt;
    while(pt!=NULL)
    {
        //用插入法怎么排序?

    }
}
void showList(Student *head)
{
    while(head)
    {
        cout<<"now the items of list are\n";
        cout<<head->id<<head->name<<head->sex<<head->age;
        head=head->next;
    }
}
main()
{
    head=Create();
    paixu(head);
    showList(head);
}
1