#include #include using namespace std;
#define null 0
#define maxsize 50
struct strlnode
;void create(struct strlnode **p, int x) /*建立雙鏈表(表頭節點)*/
void insertnode(struct strlnode **p, int i, int x) /* 在鍊錶第i個位置插入資料等於x的節點 */
int k = i;
while(k > 1 && ptemp->pnext != null)//查詢第i個結點
if (ptemp->pnext == null)
else
return ;
}void deletenode(struct strlnode **p, int i) /* 刪除鍊錶中第i個節點 */
if (i < 0)
if (i == 0 && (*p)->pnext == null)//僅有乙個結點
struct strlnode *ptemp = *p;//指向頭結點
int k = i;
while(k > 1 && ptemp != null)//查詢第i-1個結點
struct strlnode *qtemp;
qtemp = ptemp ->pnext;
if (qtemp->pnext != null)
else
}int getnodenum(struct strlnode **p) /*獲取鍊錶中節點個數*/
struct strlnode *ptemp ;
ptemp = *p;
while(ptemp != null)
return nodenum;
}void bignumberplus(struct strlnode **plus, struct strlnode **p, struct strlnode **q) /* 使用鍊錶實現大整數相加 */
if (null == q || null == *q)
struct strlnode *ptemp = *p;
struct strlnode *qtemp = *q;
while(null != ptemp->pnext)
while(null != qtemp->pnext)
int carry = 0;
struct strlnode *sum = (struct strlnode *)malloc(sizeof(struct strlnode));
sum->data = (ptemp->data + qtemp ->data)%10;
carry = (ptemp->data + qtemp ->data)/10;
sum->plast = null;
sum->pnext = null;
ptemp = ptemp->plast;
qtemp = qtemp->plast;
struct strlnode *temp;
while(null != ptemp && null != qtemp)
while(null != ptemp)
while(null != qtemp)
while (carry != 0)
*plus = sum;
return ;
}void readtolnode(struct strlnode **p, int *a, int size) /* 將陣列寫入鍊錶中,鍊錶中的資料的先後順序和陣列中的順序要保持一致 */
return;
}void writetosqlist(int *a, struct strlnode *p) /* 將鍊錶寫入陣列中,陣列中的資料的先後順序和鍊錶中的順序要保持一致 */
return;
}
雙鏈表基本操作
1.在頭接點插入指定的值 template void insertd dnode front,const t value 2.顯示所有接點數值 template void showd dnode front 3.刪除接點 template void deleted dnode lhs 4。刪除指定資...
雙鏈表基本操作
看歐立奇的 程式設計師面試寶典 的雙向鍊錶部分,發現其中建立雙向鍊錶和刪除鍊錶中得某一點的程式存在問題,現將已經除錯通過的程式貼在下面 include using namespace std define len sizeof dnode typedef struct doublenode dnod...
雙鏈表的基本操作
雙鏈表在最末端的插入和刪除要特別對待。include using namespace std typedef int elemtype 定義雙鏈表節點型別 typedef struct node dnode,dlinklist dlinklist dlinklistcreate p next nul...