?? 習(xí)題07-有序鏈表刪除重復(fù)元素.c
字號(hào):
#include "datastru.h"
#include <stdio.h>
#include <malloc.h>
void delete(LINKLIST *a){
/*在有序鏈表中刪除重復(fù)元素,保留一個(gè)*/
LINKLIST *la;
la = a->next;
while(la != NULL && la->next != NULL)
if (la->data == la->next->data)
la->next = la->next->next;
else la = la->next;
}
int count_head(LINKLIST *head){
/*帶頭結(jié)點(diǎn)的單鏈表:輸出單鏈表元素值并計(jì)數(shù)*/
int i = 0;
LINKLIST *p;
p = head->next;
printf("輸出單鏈表元素值 : ");
while(p != NULL)
{i++;
printf(" %c",p->data);
p = p->next;}
printf("\n\n");
return i;
}
LINKLIST *creatlink_order_head(LINKLIST *head)
/*建立帶頭結(jié)點(diǎn)的有序單鏈表*/
{ LINKLIST *t, *p, *q;
char ch;
t = (LINKLIST *)malloc(sizeof(LINKLIST));
head = t; t->next = NULL;
printf("單鏈表元素值為單個(gè)字符, 連續(xù)輸入,$為結(jié)束字符 : ");
while ((ch = getchar()) != '$')
{t = (LINKLIST *)malloc(sizeof(LINKLIST));
t->data = ch;
q = head; p = head->next;
while( p != NULL && p->data <= ch) {
q = p; p = p->next;}
q->next = t; t->next = p;
}
return(head);
}
main()
{
LINKLIST *head = NULL;
int num;
printf("\n 建立單鏈表\n\n");
head = creatlink_order_head(head);
fflush(stdin);
num = count_head(head);
printf("\n 刪除重復(fù)元素后\n\n");
delete(head);
num = count_head(head);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -