<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ~~~ #include<stdio.h> #include<malloc.h> #include<stdbool.h> /** **鏈表節點的定義 */ typedef struct Node{ int data;//數據域 struct Node * PNext;//指針域,存放下一個節點的地址 } Node ,* PNode ; /** **創建鏈表 */ PNode create_list() { int len,i; printf("請輸入鏈表的長度:len=\n"); scanf("%d",&len); PNode PHead=malloc(sizeof(Node)); PHead->PNext=NULL; PNode PTail=PHead;//PTail是永遠指向尾節點的指針 for(i=0;i<len;i++) { int val; printf("請輸入第 %d 個元素的值:", i+1); scanf("%d",&val); PNode PNew=malloc(sizeof(Node)); PNew->data=val; PNew->PNext=NULL; PTail->PNext=PNew; PTail=PNew; } return PHead; } /** **對鏈表進行遍歷 */ void traverse(PNode pHead) { PNode p=pHead->PNext; while(p!=NULL) { printf("%d ",p->data); p=p->PNext; } printf("\n"); } /** *判斷鏈表是否為空 */ bool isempty(PNode pHead) { if(NULL==pHead->PNext) { return true; }else{ return false; } } /** **獲取鏈表的長度 */ int list_num (PNode pHead) { int num=0; PNode p=pHead->PNext; while(p!=NULL) { num++; p=p->PNext; } return num; } /** *向鏈表中插入元素 */ bool insert_list(PNode pHead,int val ,int pos){ //需要找到第pos個位置,并且需要判斷這個位置pos是否合法 //i是p所指節點的位置,所以從一開始,為什么要pos-1呢,因為用的是while 當i=pos-1時跳出循環 int i=0; PNode p=pHead; while(NULL!=p&&i<pos-1) { i++; p=p->PNext; } //如果插入位置過大,那么P=NULL, //如果插入的位置是0或者負數,那么i>pos-1 if(i>pos-1||NULL==p) { printf("插入位置不合法\n"); return false; } PNode PNew=malloc(sizeof(PNode)); PNew->data=val; PNode temp=p->PNext; p->PNext=PNew; PNew->PNext=temp; return true; } /** **在鏈表中刪除節點 */ delete (PNode PHead,int pos , int * pval) { int i=0; PNode p=PHead; //我們要刪除p后面的節點,所以p不能指向最后一個節點 p->next!=NULL while(p->PNext!=NULL&&i<pos-1){ p=p->PNext; i++; } if(i>pos-1||p->PNext==NULL) { printf("刪除位置不合法\n"); return false; } PNode temp=p->PNext; p->PNext=temp->PNext; free(temp); } int main() { PNode PHead= create_list(); if(isempty(PHead)) printf("鏈表為空\n"); printf("鏈表的長度為:%d\n",list_num(PHead)); traverse(PHead); //insert_list(PHead,55,1); int val; delete(PHead,6,&val); traverse(PHead); return 0; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看