雙向鍊錶和單鏈表的區別就在於多了乙個前驅;有需要檢視單鏈表的在主頁裡面查詢;
雙向鍊錶**如下:
typedef class node
node;
class doublelist
~doublelist()
node *buynode(int val,node *next,node * pre)
void insert(int pos, int val)
if (head == null)
if (pos == 0)
else
node *s = buynode(val, q, p);
p->next = s;
} count++;
} void inserthead(int val)
void inserttail(int val)
void delete(int pos)
node *p = head;
node *q = p->next;
if (pos == 0)
else if (pos == 1)
else
p->pre->next = p->next;
} count--;
} void deletehead()
void deletetail()
int getcount()
void show()
cout << endl;
}private:
node *head;
int count;
};int main()
d.show();
d.delete(10);
d.show();
return 0;
}
迴圈鍊錶的和單鏈表的區別在與迴圈鍊錶首位相連。
迴圈鍊錶的**如下:
class node
;class cyclelist
~cyclelist()
node *buynode(int val,node *next)
else
return p;
} void insert(int pos, int val)
if (head == null)
node *p = head;
if (pos == 0)
node *s = buynode(val, p->next);
p->next = s;
head = s;
} else
node *s = buynode(val, p->next);
p->next = s;
} count++;
} void inserthead(int val)
void inserttail(int val)
void delete(int pos)
node *p = head;
node *q = p->next;
if (pos == 1)
else
p->next = q->next;
free(q);
} } void deletehead()
void deletetail()
void show()
cout << p->data << endl;
}private:
node *head;
int count;
};int main()
c.insert(2, 10);
c.show();
c.deletehead();
c.show();
return 0;
}
雙向鍊錶和雙向迴圈鍊錶
和單向鍊錶相比,多了乙個前驅結點。如果他為空,那麼next和prior都指向自己。而對於雙迴圈鍊錶,只需要最後乙個元素的next指向head next,head next的prior指向最後乙個節點即可。新節點s插入鍊錶,s next給p結點,s prior給p prior,然後,p prior n...
迴圈鍊錶,雙向鍊錶
迴圈鍊錶 迴圈鍊錶與順序鍊錶之間的區別 迴圈鍊錶最後乙個資料的next指標域不為空,而是指向頭結點,其他基本操作大體相同,只是在判斷表結束的條件變為判斷節點的引用域是否為頭引用 雙向鍊錶 author neosong date oct 10,2017 4 43 01 pm program of in...
鍊錶 雙向迴圈鍊錶
雙向迴圈鍊錶與單鏈表一樣,都是邏輯連續 物理不連續的儲存方式,但它的效果要遠遠優於單鏈表,其結構如下 雙向迴圈鍊錶首先要有乙個頭節點,頭節點中不存放資料,真正的資料從頭節點的下乙個節點開始存放 然後每乙個節點都有兩個指標,分別指向前乙個節點和後乙個節點 最後頭尾相連,就成了雙向迴圈鍊錶。includ...