帮看看有序单链表的合并为什么合并不成功
#include<iostream>#include<list>
#include<algorithm>
#include<vector>
#include<conio.h>
using namespace std;
bool youxu(list<int>&ls){
list<int>::iterator it1=ls.begin(),it2=++it1;it1=ls.begin();
if(*it1<*it2){
while(it2!=ls.end()){
if(*it1>*it2)
return false;
++it1;
++it2;
}
return true;
}
else if(*it1>*it2){
while(it2!=ls.end()){
if(*it1<*it2)
return false;
++it1;
++it2;
}
return true;
}
else{}
}
void hebing(list<int>&ls1,list<int>&ls2){
vector<int>v;
list<int>::iterator it2=ls2.begin(),it1=ls1.begin();
while(it1!=ls1.end()){
v.push_back(*it1);
++it1;
}
while(it2!=ls2.end()){
v.push_back(*it2);
++it2;
}
sort(v.begin(),v.end());
ls1.clear();
vector<int>::iterator i=v.begin();
for(;i!=v.end();++i)
ls1.push_front(*i);
}
void show(list<int>&ls){
cout<<"链表元素为:";
list<int>::iterator it=ls.begin();
for(;it!=ls.end();++it)
cout<<*it<<" ";
}
int main(){
int n;
list<int>ls1,ls2;
cout<<"有序输入链表1数据-1结束: ";
while(cin>>n&&n!=-1)
ls1.push_back(n);
while(youxu(ls1)==false) {
cout<<"请<有序>输入链表1数据-1结束: ";
ls1.clear();
while(cin>>n&&n!=-1)
ls1.push_back(n);
}
show(ls1);
cout<<endl;
cout<<"有序输入链表2数据-1结束: ";
while(cin>>n&&n!=-1)
ls2.push_back(n);
while(youxu(ls2)==false) {
cout<<"请<有序>输入链表1数据-1结束: ";
ls2.clear();
while(cin>>n&&n!=-1)
ls2.push_back(n);
}
show(ls2);
cout<<endl;
hebing(ls1,ls2);
cout<<"有序合并后为:";
show(ls1);
return 0;
}