C 資料結構 鍊錶

2021-09-24 21:51:45 字數 2397 閱讀 7440

// 資料結構2-鍊錶.cpp : 此檔案包含 "main" 函式。程式執行將在此處開始並結束。

//#include "pch.h"

#include using namespace std;

typedef struct lnode //定義乙個節點

*list;

void createla(list &l, int *n,int length) //建立鍊錶la,引數1為la的位址,引數2為初始化la用的陣列,引數三為陣列長度

cout << endl;

}void createlb(list &l, int *n, int length)

}void sort(list &l,int len)//將鍊錶排序,引數len為長度,以下皆如此

} }}

void display(list l,int len)//向螢幕列印鍊錶

cout << endl;

cout << "當前線性表長度:" << i << endl; }}

void mergelists(list l1, list l2,list &l3,int len1,int len2,int &len3)//合併鍊錶la和lb成新鍊錶lc

for (i = 0; i < len2; i++)

len3 = len1 + len2;

}void serchofdata(list l, int n)//按值查詢

if (p->pnext != null)

if (i>n) }}

void serachofindex(list l, int n) //按址查詢

} if (key)

cout << "第" << index << "位的資料值是" << p->data << endl; }}

void popofnum(list &l,int &n) //按值刪除

p = p->pnext;

} if (key)

if (!key)

}}void popofindex(list &l, int &n) //按址刪除

} list p=l->pnext;

int i = 0;

while (true)

p = p->pnext;

} if (key)

}}void insert(list l, int &n) //向鍊錶插值

list s = new lnode;

s->data = num[i];

s->pnext = p->pnext;

p->pnext = s;

n++;

} delete num;

}int main()

; createla(la, n1,10);

cout << "la:";

display(la, 10);

list lb;

int n2 = ;

createlb(lb, n2, 11);

cout << "lb:";

display(lb, 11);

list lc;

int len1=10,len2=11,len3 = 21;

mergelists(la, lb, lc, 10, 11,len3);

sort(lc, len3);

cout << "lc:";

display(lc, len3);

cout << "以下是線性表lc的操作:" << endl;

serchofdata(lc, len3);

serachofindex(lc, len3);

popofnum(lc, len3);

cout << "lc:";

display(lc, len3);

popofindex(lc, len3);

cout << "lc:";

display(lc, len3);

insert(lc, len3);

cout << "lc:";

display(lc, len3);

cout << "la進行插值";

insert(la, len1);

cout << "新la:";

display(la, len1);

cout << "lb進行插值";

insert(lb, len2);

cout << "新lb:";

display(lb, len2);

mergelists(la, lb, lc, len1, len2, len3);

sort(lc, len3);

cout << "新lc:";

display(lc, len3);

return 0;

}

資料結構 鍊錶(C )

typedef int rank define listnodeposi t listnode template class listnode listnode t e,listnodeposi t p null,listnodeposi t s null data e prenode p back...

C 資料結構 鍊錶

理論基礎 鍊錶是用一組任意的儲存單元來儲存線性表中的資料元素。如果結點的引用域只儲存該結點直接後繼結點的儲存位址,則該鍊錶叫單鏈表 singly linked list 單鏈表由頭引用h唯一確定。頭引用指向單鏈表的第乙個結點,也就是把單鏈表第乙個結點的位址放在h中。c 實現 1介面 引用線性表的介面...

資料結構(C 鍊錶

鍊錶結構體的定義 struct ndoe typedef struct node node,pnode 頭插法插入結點 1.建立頭結點,並分配空間 2.建立新結點,新節點 next指向上乙個節點,頭結點 next指向新結點 pnode list headinsert pnode head pnode...