正文之前
熟悉我的人都知道,我是不屑于說廢話的, 所以,就不廢話了。另外,本系列估計快要完了,因為我估計要去讀博士了,計算機的喲,以后的文章就不傾向于小白文了,能看懂的受眾估計也不多,多半簡書就成了科普和流水賬,感情戲的首發(fā)地點,至于高深的文章應(yīng)該CSDN,簡書,公眾號,掘金,博客園等地方都會發(fā)一遍~喜歡我的小伙伴們可以隨便關(guān)注一個,不過簡書應(yīng)該還是比較齊全的吧。畢竟都這么久了,而且簡書對我也有特別的意義,所以我還是舍不得丟棄的
~
正文
本段程序?qū)崿F(xiàn)了:刪除帶頭結(jié)點的單鏈表中所有Data為X的節(jié)點,而且跟王道的不一樣的是,我只用了一個指針,另外,王道的P037的第一題,我運行了一下,沒法跑出來,所以估計有點問題,然后第二題他用了兩個指針交替,我就用一個,個人感覺還不錯,起碼空間復雜度比他的低~~ 走你
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 4
//注:定義隊列結(jié)構(gòu)體及其指針
typedef struct List
{
int Data;
struct List *next;
} List, *PtrL;
void Insert(PtrL ptrl,int data)
{
PtrL s;
s=(List *)malloc(sizeof(List));
s->Data=data;
s->next=ptrl->next;
ptrl->next=s;
}
void ShowList(PtrL ptrl)
{
PtrL show;
show=ptrl;
while(show)
{
int num=show->Data;
printf("\n##########\n#");
printf("\t%d\t",num);
printf("#\n");
printf("##########\n");
printf("\t||\n\t||\n\t||\n\t||");
printf("\n ~~~~~ " );
printf("\n VVV " );
printf("\n V " );
printf("\n" );
show=show->next;
}
printf("\tNULL\n\n\n\n");
}
void Del(PtrL ptrl)
{
PtrL D;
D=ptrl->next;
ptrl->next=D->next;
printf("\n%d\n",D->Data);
free(D);
}
void DelX(PtrL ptrl,int x)
{
PtrL p=ptrl;
if(p->next==NULL) return;
else if (p->next->Data==x)
{
Del(p);
DelX(p, x);
}
else
DelX(p->next,x);
}
int main()
{
PtrL ptrl;
ptrl=(List *)malloc(sizeof(List));
ptrl->next=NULL;
Insert(ptrl,2);
Insert(ptrl,5);
Insert(ptrl,3);
Insert(ptrl,8);
Insert(ptrl,5);
Insert(ptrl,11);
Insert(ptrl,9);
Insert(ptrl,7);
ShowList(ptrl);
DelX(ptrl,5);
ShowList(ptrl);
return 0;
}

運行結(jié)果如下:
##########
# 0 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 7 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 9 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 11 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 5 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 8 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 3 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 5 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 2 #
##########
||
||
||
||
~~~~~
VVV
V
NULL
5
5
##########
# 0 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 7 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 9 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 11 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 8 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 3 #
##########
||
||
||
||
~~~~~
VVV
V
##########
# 2 #
##########
||
||
||
||
~~~~~
VVV
V
NULL
Program ended with exit code: 0
正文之后
薇薇pig 對不起啦。等我跟老師面談完,如果順利我周末就定火車票去找你,如果不順利,我估計還要到處跑著去找老師,因為快簽訂保研協(xié)議書了,到時候后悔什么的沒有余地了。雖然我知道你很氣,很傷心,但是從理性角度來說,我還是傾向于先處理我未來五年的大方向的問題,所以先委屈你了,等周六給你個驚喜,不過這次不敢搭夜車去找你了,太難受了?。。。∩洗尾铧c死在火車站!