雙向迴圈鍊錶
main.c
#include
#include "linklist.h"
int main()
else
//頭插
insert_head(ls, 1);
insert_head(ls, 5);
insert_head(ls, 12);
insert_head(ls, 12);
insert_head(ls, 15);
insert_head(ls, 18);
insert_head(ls, 18);
insert_head(ls, 21);
display(ls);
//尾插
insert_last(ls, 1);
insert_last(ls, 5);
insert_last(ls, 12);
insert_last(ls, 12);
insert_last(ls, 15);
insert_last(ls, 18);
display(ls);
//隨機插入
insert_pos(ls, 3, 11);
display(ls);
//指定位置刪除
delete_pos(ls, 3);
display(ls);
//逆序鍊錶
reverse(ls);
display(ls);
destroy(ls);
return 0;
}linklist.h
#ifndef _link_list
#define _link_list
typedef enum bool;
typedef int data;
typedef struct _node
node;
typedef struct _list
list;
//建立鍊錶
list *creatlist();
//頭插
bool insert_head(list* ls, data data);
//尾插
bool insert_last(list* ls, data data);
//隨機插入
bool insert_pos(list* ls, int pos, data data);
//刪除指定位置檔案
bool delete_pos(list* ls, int pos);
//逆序鍊錶
bool reverse(list *ls);
//列印鍊錶
void display(list *ls);
void destroy(list *ls);
#endif //_link_list
list.c
#include "linklist.h"
#include
#include
//建立鍊錶
list *creatlist()
ls->head->next = ls->head;
ls->head->pre = ls->head;
return ls;
}//頭插
bool insert_head(list* ls, data data)
node *node = (node *)malloc(sizeof(node)/sizeof(char));
if(null == node)
node->data = data;
ls->head->next->pre = node;
node->next = ls->head->next;
node->pre = ls->head;
ls->head->next = node;
return true;
}//尾插
bool insert_last(list* ls, data data)
node *node = (node *)malloc(sizeof(node)/sizeof(char));
if(null == node)
node->data = data;
node->next = null;
node *tmp = ls->head;
while(tmp->next != ls->head)
tmp->next = node;
node->pre = tmp;
node->next = ls->head;
ls->head->pre = node;
return true;
}//隨機插入
bool insert_pos(list* ls, int pos, data data)
node *node = (node *)malloc(sizeof(node)/sizeof(char));
if(null == node)
node *tmp = ls->head;
int i = 0;
for (i = 0; i < pos-1; i++)
}node->data = data;
tmp->next->pre = node;
node->next = tmp->next ;
tmp->next = node;
node->pre = tmp;
return true;
}//指定位置刪除
bool delete_pos(list* ls, int pos)
node *tmp = ls->head;
int i = 0;
for (i = 0; i < pos-1; i++)
}node *p = tmp->next;
tmp->next = p->next;
p->next->pre = tmp;
free(p);
return true;
}//列印鍊錶
void display(list* ls)
node *tmp = ls->head->next; //第乙個節點
while(tmp != ls->head)
printf ("\n");
}//逆序
bool reverse(list *ls)
node *cur = ls->head->next;
while(cur->next != ls->head)
ls->head->next->next = ls->head;
ls->head->next = cur;
cur->next = cur->pre;
cur->pre = ls->head;
return true;
}//銷毀鍊錶
void destroy(list *ls)
迴圈鍊錶和雙向鍊錶的結合,雙向鍊錶和迴圈鍊錶都是由單向鍊錶發展出來的。
Python學習之路10 數字
數字提供了標量儲存和直接訪問。數字是不可更改型別,也就是說變更數字的值會生成新的物件。python支援多種數字型別 整型 長整型 布林型 雙精度浮點型 十進位制浮點型和複數。可以通過賦值來建立或更新數字物件。建立數字物件 如 var 1 更新數字物件 如 var 2 刪除數字物件 如 del var...
Linux學習之路
一直想學習linux,就其原因,一是懂這個的都被認為水平比較高,二是懂這個的工資也不低,這兩點我也是比較看重的。想學linux也不是一件簡單的事,因為用windows的東西太久了,從3.1到95 98 se nt 2000 me xp 2003,直至最新的windows 7 2008等,全算下來,有...
Linux學習之路
bios 開機主動執行的韌體,會識別第乙個可開機的裝置 mbr 第乙個可開機裝置的第乙個扇區內的主要啟動記錄區塊,內含開機管理程式 開機管理程式 boot loader 一支可讀取核心檔案來執行的軟體 核心檔案 開始作業系統的功能。下面是網上比較好的開機流程,僅供參考 將資料同步寫入磁碟的方法 sy...