在一个有头结点的单链表中删除值为N的结点!要求:值N可以自由变换,输出删除前和删除后的结果

来源:百度知道 编辑:UC知道 时间:2024/07/03 03:29:39
用C编程 。。

struct link_list {
int number;
struct link_list *next; //to the next structure
};

typedef struct link_list ELEMENT;
typedef ELEMENT *LINK;

创建链表时要有头链,head
删除,head是作为参数的头链
function deleteElement(int tem,LINK head){
LINK tail=head;
while ((tail)&&(tail->number!=tem))
tail=tail->next;
if (tail==head){ //element is the head of list
if (tail->next==NULL) //there are only one element in the list
head=NULL;
else
head=tail->next;
}
else if (tail->next==NULL){ //element is the end of list
LINK tail2;
tail2=head;
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=NULL;
}
else{ //element is in the middle of the list
LINK tail2;
tail2=head;
while (tail2->next!=tail)
tail2=tail2->next;
tail2->next=tail->next;
}
}

显示
function print_list(LI