设顺序表L中的元素递增有序.试写一算法,将数据元素x插入到顺序表L的适当位置,以保持该表的有序性.

问题描述:

设顺序表L中的元素递增有序.试写一算法,将数据元素x插入到顺序表L的适当位置,以保持该表的有序性.

struct list *p,*q,*s,*head;p = head;while(p != NULL){ if(x > p->data){q = p; p = p->next;}else{s = (struct list*)malloc(sizeof(struct list));s->data = x;q->next = s;s->next = p;}}