#include <iostream>
#include "algorithm"
#include "list"
using namespace std;
/* 创建一个单链表 */
struct Node{
int data;
Node *next;
};
void creatList(Node *head,int arr[],int n){
Node *p=head;
for (int i = 0; i < n; ++i) {
Node *p1=new Node;
p1->data=arr[i];
p1->next= nullptr;
p->next=p1;
p=p1;
}
}
//链表排序
Node *sortList(Node *head){
if(head== nullptr||head->next== nullptr)return head;
list<int>L;
for (Node *p=head;p!= nullptr;p=p->next) {
L.push_back(p->data);
}
L.sort();
for(Node *p=head;p!= nullptr;p=p->next){
p->data=L.front();
L.pop_front();
}
return head;
}
void ListPrintf(Node *head){
Node *p=head->next;
while(p!= nullptr) {
cout<<p->data<<" ";
p=p->next;
}
cout<<"\n";
}
int main()
{
ios::sync_with_stdio(false); //加快输入的时间
cin.tie(0);
cout.tie(0);
Node *head= nullptr;
head =new Node;
head->next= nullptr;
head->data=0;
int n;
cin>>n;
int a[n];
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
creatList(head,a,n);
ListPrintf(head);
head= sortList(head);
ListPrintf(head);
return 0;
}