一道数据结构试验

来源:百度知道 编辑:UC知道 时间:2024/06/06 02:49:32
线性表(11、16、16、27、39、39、62、62、62、71、88、97)采用顺序存储结构(也可采用单链表存储结构),编写程序完成下列功能:
1。将线性表中相同的元素删除,删除后的线性表为(10、16、27、39、62、71、88、97)
2。在线性表中插入X,使得插入后的线性表仍然有序
十分紧急!!!!!!
谢谢

/* in ANSI C,已测 */
/* 插入和删除元素的操作,最好使用单链表 */

#include <stdio.h>
#include <malloc.h>

typedef struct LNode {
int data;
struct LNode *next;
} LNode, *LinkList;

void insertByOrder(LinkList *pL, int e) {
//按顺序插入
LNode *prev, *curt = (*pL)->next;
LNode *pNode = (LNode *)malloc(sizeof(LNode));
pNode->data = e;
if(curt == NULL) {
pNode->next = NULL;
(*pL)->next = pNode;
return;
}
while(curt != NULL && curt->data < e) {
prev = curt;
curt = curt->next;
}
pNode->next = curt;
prev->next = pNode;
}

void deleteCommon(LinkList *pL) {
//删除相同元素
LNode *prev, *curt = (*pL)->next;
while(curt != NULL) {
prev = curt;
curt = curt->next;
if(curt != NULL && prev->data == curt->data) {
curt