[cpp]view plain
copy
// 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;
} //單鏈表的測長
intlength(node *head)
return
len;
} //列印單鏈表
void
print(node *head)
while
(p!=null)
//遍歷鍊錶
} //查詢單鏈表pos位置的節點,返回節點指標
//pos 從o開始,0 返回head節點
node *search_node(node *head,int
pos)
if(0==pos)
//在head位置,返回head
if(p==null)
while
(--pos)
} return
p;
} //單鏈表節點插入
//在單鏈表中某個位置(第pos個節點)後面插入節點,返回煉表頭指標
//pos 從0開始計算,0表示插入head節點後面
node *insert_node(node *head,int
pos,
intdata)
while
(pos)
if(q!=null)
return
head;
} //刪除單鏈表的pos位置的節點,返回煉表頭指標
//pos從1開始計算,1表示刪除head後的第乙個節點
node *delete_node(node *head,int
pos)
while
(--pos)
if(q!=null && q->next!=null)
return
head;
} int
_tmain(
intargc, _tchar* argv)
system("pause"
);
delete
head;
return
0;
}
單鏈表建立,插入,刪除,查詢,遍歷操作
單鏈表建立,插入,刪除,查詢,遍歷操作 link.cpp 定義控制台應用程式的入口點。單鏈表 include stdafx.h include include using namespace std typedef struct node node 建立單鏈表 node create p new n...
單鏈表建立,插入,刪除,查詢,遍歷操作
link.cpp 定義控制台應用程式的入口點。單鏈表 include stdafx.h include include using namespace std typedef struct node node 建立單鏈表 node create p new node p data a p next ...
順序表的建立 插入 刪除 查詢 遍歷操作
題目 設計乙個順序錶類,實現類中的基本操作 建構函式 刪除 插入 按位置查詢 按值查詢 輸出順序表 實驗內容 1 建立乙個順序表l 輸出該表中各元素的值 2 在順序表l中第i 4的位置插入元素68 3 刪除順序表l中第i 7的資料元素,並輸出被刪除的元素值 4 輸出順序表l中所有元素。include...