關於鍊錶的增刪改查~
#pragma once
#include#include#includetypedef int datatype;
typedef struct slistnode
slistnode;
//初始化
void slistinit(slistnode **ppfirst)
//銷毀
void slistdestroy(slistnode **ppfirst)
*ppfirst = null;
}//申請空間
slistnode *createnewnode(int data)
//尾插
void pushback(slistnode **ppfirst, datatype data)
slistnode *pnode = *ppfirst;
while (pnode->pnext!=null)
pnode->pnext = pnewnode;
}//頭插
void pushfront(slistnode **ppfirst, int data)
//頭刪
void popfront(slistnode **ppfirst)
//尾刪
void popback(slistnode **ppfirst)
slistnode *pnode=*ppfirst;
while (pnode->pnext->pnext != null)
free (pnode->pnext);
pnode->pnext = null;
}//查詢
slistnode *find(slistnode *pfirst, int data)
} return null;
}//按節點插入
void insert(slistnode **ppfirst, slistnode *ppos, datatype data)
while (pnode->pnext != ppos)
slistnode *pnewnode = createnewnode(data);
pnode->pnext = pnewnode;
pnewnode->pnext = ppos;
}//按節點刪除
void erase(slistnode **ppfirst,slistnode *ppos)
slistnode *pcur;
for (pcur = *ppfirst; pcur != ppos; pcur = pcur->pnext)
pcur->pnext = ppos->pnext;
free(ppos);
}//刪除第一次遇見的
void remove(slistnode **ppfirst, datatype data)
}//刪除所有出現的
void removeall(slistnode **ppfirst, datatype data)
else
} if ((*ppfirst)->data == data)
}//列印
void print(slistnode *pfirst)
printf("null\n");
}void slist()
else
print(pfirst);
//根據資料刪除
//remove(&pfirst, 3);
removeall(&pfirst, 3);
print(pfirst);
//銷毀
slistdestroy(&pfirst);
}
資料結構之雙向鍊錶(增刪改查)
package com.ws.鍊錶.雙向鍊錶.增刪改查 public class doublelinkelisttest 建立乙個雙向鍊錶的類,每個物件就是乙個節點 class node 顯示方法 override public string tostring 建立管理鍊錶的類 class doub...
mysql增刪改查鍊錶 鍊錶的增刪改查
include include 先定義鍊錶裡面的元素。typedef struct nodemynode 定義整個鍊錶。typedef struct linkmylink int isempty to mylink mylink mylink 判斷鍊錶是否為空。int push to mylinki...
資料結構 鍊錶的增刪改查底層實現
鍊錶的底層 實現 增刪改查 實現如下 package cn.datastructures.stack public class linkedlistdemo public note e e public note public string tostring private note dummyhe...