單鏈表建立,插入,刪除,查詢,遍歷操作

2021-06-04 22:37:18 字數 1283 閱讀 2164

單鏈表建立,插入,刪除,查詢,遍歷操作

// link.cpp : 定義控制台應用程式的入口點。

//單鏈表

#include "stdafx.h"

#include #include using namespace std;

typedef struct node node;

//建立單鏈表

node *create()

p=new node;

p->data=a;

p->next=null;//鍊錶的最後乙個指標為null

if (++i==1) //鍊錶只有乙個元素

else

q=p;//q指向末節點

} return head;

}//單鏈表的測長

int length(node *head)

return len;

}//列印單鏈表

void print(node *head)

}//查詢單鏈表pos位置的節點,返回節點指標

//pos 從o開始,0 返回head節點

node *search_node(node *head,int pos)

while (pos)

if (q!=null)

return head;

}//刪除單鏈表的pos位置的節點,返回煉表頭指標

//pos從1開始計算,1表示刪除head後的第乙個節點

node *delete_node(node *head,int pos)

if (q!=null && q->next!=null)

return head;

}int _tmain(int argc, _tchar* argv)

list;

void bubble_sort(list *&l);//鍊錶的氣泡排序

void dis_list(list *&l);//遍歷單鏈表

int main()

p->next=null;

printf("排序前:\t");

dis_list(s);

//排序

bubble_sort(s);

printf("排序後:\t");

dis_list(s);

return 0;

}void dis_list(list *&l)

printf("\n");

}void bubble_sort(list *&l)

}}}

單鏈表建立,插入,刪除,查詢,遍歷操作

link.cpp 定義控制台應用程式的入口點。單鏈表 include stdafx.h include include using namespace std typedef struct node node 建立單鏈表 node create p new node p data a p next ...

單鏈表建立,插入,刪除,查詢,遍歷操作!!!!

cpp view plain copy link.cpp 定義控制台應用程式的入口點。單鏈表 include stdafx.h include include using namespace std typedef struct node node 建立單鏈表 node create p new n...

順序表的建立 插入 刪除 查詢 遍歷操作

題目 設計乙個順序錶類,實現類中的基本操作 建構函式 刪除 插入 按位置查詢 按值查詢 輸出順序表 實驗內容 1 建立乙個順序表l 輸出該表中各元素的值 2 在順序表l中第i 4的位置插入元素68 3 刪除順序表l中第i 7的資料元素,並輸出被刪除的元素值 4 輸出順序表l中所有元素。include...