#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef struct node{
int data;
struct node * NEXT;
}elemsn;
ELEMSN * Createlink (int a[],int n) {
int i;
ELEMSN * h=null, * p;
for (i=n-1;i>=0;i--) {
p= (ELEMSN *) malloc (sizeof (ELEMSN));
P->data =a[i];
p->next=h;
H=p;
}
return h;
}
void Printlink (ELEMSN * h) {
ELEMSN * p;
for (P=h;p;p=p->next)
printf ("%d\n", p->data);
}
elemsn* Selectsont (elemsn*h) {
ELEMSN*P,*Q,*PM,*QM,*H1; //pq Pointer Linkage, PM max pointer, QM maximum pointer of the previous node, H1 head node
H1=null;
while (h) { //end condition is null for the head pointer
for (Pm=q=h,p=h->next;p;q=p,p=p->next) {
if (pm->data>p->data) {
Pm=p;
qm=q;
}
} //for end, PM refers to the maximum value node .
if (pm-h)
qm->next=pm->next; //Not head pointer
Else
h=h->next; //Is the head pointer
pm->next=h1; //maximum value placed on the head node
H1=PM; //Set head pointer
}
return H1;
}
int main (void) {
int a[n]={10,2,80,5,4};
ELEMSN * HEAD;
Head=createlink (a,9);
Head=selectsont (head);
Printlink (head);
}
List ascending sort (descending)