雙向鍊錶 建立 列印 測長 查詢 插入 刪除

2021-09-10 04:52:20 字數 1389 閱讀 2234

#include using namespace std;

typedef struct dbnode

dbnode;

//根據資料建立節點

dbnode *create(int data)

//插入新節點,總是在表尾插入;返回表頭節點;

q->right = pnode;

pnode->left = q;

return head ;

}//實現雙向鍊錶的測長

int getlength(dbnode *head)

else

p = p->right;

} }//printf("%d\n",count);

return count;

}//雙向鍊錶的列印

void dbprint(dbnode *head)

}//實現雙向鍊錶節點的查詢

dbnode *findnode(dbnode *head,int data)

else

--length;

} }return null;

}//雙向鍊錶的插入

dbnode *insertnode(dbnode *head,int data,int pos)

while(pos>0&&length>pos)

if(p->right != null)

else

return head;

}//雙向鍊錶節點的刪除

dbnode *deletenode(dbnode* head ,int data)

} else if(pnode->right ==null)

else

}free(pnode);

return head;

}int main()

findnode(head,3);

insertnode(head,25,8);

head = deletenode(head,9);

dbprint(head);

return 0;

}

the list find node:3

the list find node:9

the list delete node data:9

the list data :0

the list data :1

the list data :2

the list data :3

the list data :4

the list data :5

the list data :6

the list data :7

the list data :8

鍊錶的基本操作,建立,測長,刪除,列印,插入

老早就想自己寫寫鍊錶的基本操作的實現,寫寫來練練手。include include includeusing namespace std typedef struct nodenode 鍊錶的建立 node createlist int n head head next 第乙個有資料的給頭指標 p1...

雙向鍊錶的建立 結點的插入 刪除與列印

1 雙向鍊錶的建立與單向鍊錶是類似的。其核心也是結點的記憶體申請以及結點間前後趨關係。建立如下雙鏈表 建立雙向鍊錶 pnode createdoublelist type val,int n head pre null head next null temp head for int i 0 ida...

資料結構 9 雙向鍊錶建立 輸出和測長

雙向鍊錶,建立單鏈表,並輸出鍊錶,查詢鍊錶中某個結點元素,測試鍊錶的長度 結點個數 雙向鍊錶只是多了乙個左指標,其實作用不大,它的左指標一般也用的少,雙向鍊錶是後面樹的基礎。includeusing namespace std struct node node結構體,裡面有兩個個node指標,用來指...