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

2021-07-05 22:50:33 字數 974 閱讀 6461

老早就想自己寫寫鍊錶的基本操作的實現,

寫寫來練練手。

#include#include#includeusing namespace std;

typedef struct nodenode;

//鍊錶的建立

node *createlist(int n)

head=head->next;//第乙個有資料的給頭指標;

p1->next=null;

return head;

}//鍊錶的測長

int length(node *head)

return len;

}//鍊錶的列印

void listprintf(node *head)

}//鍊錶反轉

node *reverse(node *head)

head->next=null;

head=p1;

return head;

}//鍊錶刪除;刪除第n個節點

node *deletenode(node *head,int n)

p1=p2;

} return head;

}//鍊錶刪除;刪除資料與num相等的節點,或沒有此節點;

node *deletelist2(node *head,int num)

if(num==p1->data )

else

}else

return head;

}// 鍊錶的插入;鍊錶是順序排列的;並沒有要求輸入要插入的位置;輸入插入的資料;

node *insertnode(node *head,int loc)

if(p0->data <=p1->data )

else

}else //插到尾部;

return head;

}

int main()

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

include using namespace std typedef struct dbnode dbnode 根據資料建立節點 dbnode create int data 插入新節點,總是在表尾插入 返回表頭節點 q right pnode pnode left q return head 實...

鍊錶的建立 刪除節點 側長和列印

鍊錶的建立 刪除節點 側長和列印 include include include struct linknode typedef linknode linklist linknode addnode linknode p,int data int list length linklist head ...

鍊錶的建立,插入,刪除,輸出基本操作

include include struct student 定義乙個學生結點,結點包括值域和指標域 typedef struct student list list createlist list insertnode list h,list s list deletenode list h,lo...