1 #include <cstring> 2 #include <cstdio> 3 using namespace std; 4 5 typedef int type; 6 7 template<class T> 8 struct Node { 9 T data; 10 Node *next; 11 Node<T>() { 12 data = 0; 13 next = NULL; 14 } 15 }; 16 17 Node<type> *head = new Node<type>(); 18 19 template<class T> 20 void add(Node<T> *n0) { 21 Node<T> *pr = head; 22 Node<T> *now = head -> next; 23 while(now) { 24 if(now -> data > n0 -> data) { 25 n0 -> next = now; 26 pr -> next = n0; 27 return ; 28 } 29 pr = now; 30 now = now -> next; 31 } 32 pr -> next = n0; 33 } 34 35 template<class T> 36 void print() { 37 Node<T> *p = head -> next; 38 while(p) { 39 printf("%d ", p -> data); 40 p = p -> next; 41 } puts(""); 42 } 43 44 45 int main() { 46 int n; 47 type x; 48 while(cin >> n) { 49 cin >> x; 50 Node<type> *p = new Node<type>(); 51 p -> data = x; 52 p -> next = NULL; 53 head -> next = p; 54 for(int i = 1; i < n; i++) { 55 cin >> x; 56 Node<type> *n0 = new Node<type>(); 57 n0 -> data = x; 58 add<type>(n0); 59 } 60 print<type>(); 61 } 62 }