#include #include using namespace std;

typedef struct linknode{ int data; linknode * next; }linknode, *node;

int Partition(vector &a,int left,int right){ int pivot = a[left]; while(left < right){ while(a[right] >= pivot && left < right) right--; a[left] = a[right]; while(a[left] <= pivot && left < right) left++; a[right] = a[left]; } a[left] = pivot; return left; }

void QuickSort(vector &a, int left, int right){ if(left < right){ int pivotpos = Partition(a, left, right); QuickSort(a, left, pivotpos); QuickSort(a, pivotpos + 1, right); } } int main(){ int num; cin >> num; vector a(num); for(int i = 0;i < num; i++) cin >> a[i]; QuickSort(a, 0, num - 1); int c = num - 1; node head = (node)malloc(sizeof(linknode)); head->next = NULL; while(c != -1){ node p = (node)malloc(sizeof(linknode)); p->data = a[c]; p->next = head->next; head->next = p; c--; }
while(head->next != NULL){ head = head->next; cout << head->data << " "; } }