//链表排序
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
int value;
struct Node *next;
}Node;
Node *getnewnode(int val){
Node *p=(Node *)malloc(sizeof(Node));
p->next=NULL;
p->value=val;
return p;
}
int getlen(Node *head){
int count=0;
Node *p=head;
while(p){
p=p->next;
count++;
}
return count;
}
void bubber(Node *head){
if(head==NULL||head->next==NULL) return ;
//链表冒泡排序
int swapped;
Node* current;
Node* last = NULL;
do {
swapped = 0;
current = head;
while (current->next != last) {
if (current->value > current->next->value) {
// 交换节点的值
int temp = current->value;
current->value = current->next->value;
current->next->value = temp;
swapped = 1;
}
current = current->next;
}
last = current;
} while (swapped);
}
void insertNode(Node **head,int val){
Node *newnode=getnewnode(val);
if(*head==NULL){
*head=newnode;
return ;
}
Node *p=*head;
while(p->next){
p=p->next;
}
p->next=newnode;
return ;
}
void clear(Node *head){
if(head==NULL) return;
for(Node *p=head,*q;p;p=q){
q=p->next;
free(p);
}
return ;
}
int main(void){
int n;
scanf("%d",&n);
Node *head=NULL;
int num[101];
for(int i=0;i<n;i++){
scanf("%d",&num[i]);
insertNode(&head,num[i]);
}
bubber(head);
Node *cur=head;
printf("Head");
while(cur){
printf("->%d",cur->value);
cur=cur->next;
}
clear(head);
return 0;
}