資料結構篇 單鏈表基礎操作(二)

2021-08-30 21:37:29 字數 680 閱讀 6669

已知帶頭結點的單鏈表,存放一組整型數

①建立n個元素的單鏈表

②計算鍊錶中值大於x的結點的個數,int countx(lnode *head,int x)

③兩個鍊錶ha,hb存放整型數,每個鍊錶中無相同元素,hc=ha∩hb,即ha和hb中相同元素放入hc中,void intersection(lnode *ha,lnode *hb,lnode *&hc)

#include using namespace std;

typedef struct link inode;

class test ;

inode * test:: t_createlist(inode * head,int n)

return head;

}int test::countx(inode *head , int x)

p = p->next;

} return count;

}void test :: intersection(inode *ha,inode *hb,inode *&hc)

hbtemp = hbtemp->next;

} hatemp = hatemp->next; }}

void test::showlink(inode *h)

}int main()

資料結構基礎總結(二)單鏈表

1 鍊錶的基本結構 鍊錶的各個節點不一定是連續存放的 鍊錶分為帶頭節點和不帶頭節點,根據需求決定 2 單向鍊錶的增刪改查 單向鍊錶的增刪改查 class node override public string tostring class singlelist temp temp.next temp...

資料結構 單鏈表 基礎

在實現單鏈表的基本功能後 單鏈表的幾個基本問題 1.比較順序表和煉表的優缺點,說說它們分別在什麼場景下使用?順序表 物理位置相鄰 優點 在一段記憶體中用陣列連續存放,所以方便隨機查詢元素。缺點 動態開闢,容易造成記憶體浪費,需要乙個元素,開闢過多。前面新增元素時,要逐個挪動後面的每個元素,較麻煩。場...

資料結構基礎 單鏈表

關於單鏈表的一些基本操作,以下為基本思路 首先看一張直觀圖 鍊錶的結構體定義如下 為簡便,這裡的elemtype採用int 單鏈表 typedef struct lnode linklist 接下來肯定就是建立鍊錶,而目前建立單鏈表分為兩種方式,分別是 頭插法 與 尾插法 首先看圖示 清楚明白 我們...