#include <iostream>
using namespace std;
struct node{
int val;
node * next;
};
void print(node * head){
if(head==NULL ||head->next==NULL){
cout<<"链表中已经无元素";
return;
}
cout<<"打印列表:";
node * p=head->next;
while(p){
cout<<p->val<<" ";
p=p->next;
}
cout<<endl;
}
int main(){
int n;
node * head=new node;
head->next=NULL;
cout<<"请输入数字";
while(cin>>n){
node * cur=new node;
cur->val=n;
node *pre=head;
if(head->next==NULL){
head->next=cur;
cur->next=NULL;
print(head);
continue;
}
node *p=head->next;
while(p->val<n){
pre=p;
p=p->next;
if(p==NULL) break;
}
pre->next=cur;
cur->next=p;
print(head);
cout<<"请输入数字"<<endl;
}
return 0;
}