C++作业啊,大家帮忙,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/19 01:40:23
1. 设计函数void InsertSort(Node *& Head);以插入排序方法对链表中的数据进行升序排序(从小到大);
2. 设计函数设计函数void SelectSort(Node *& Head);以简单选择排序方法对链表中的数据进行升序排序(从小到大);
做这两道题,我快把脑袋想破了,高手支招啊,50分不成敬意

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class node
{public:
long a;
node *next;
};
main()
{node *head;
vector<long>V(0);
vector<long>::iterator psdz;
head=new node;
while (head->a)
{cin>>head->a;
V.insert(V.begin(),head->a);
}
sort(V.begin(),V.end());
psdz=V.begin();
while (psdz!=V.end())
{
cout<<*psdz<<endl;
psdz++;
}
delete head;
}
第一个
#include <iostream.h>
class node
{public:
long a;
node *next;
};
main()
{node *head,*p,*s;
s=new node;
cin>>s->a;
head=NULL;
while (s->a)
{if (head==NULL) head=s;
else p->next=s;
p=s;
s=new node;
cin>>s->a;
}
p->next=NULL;
p=head;
dele