單鏈表基本操作

2021-06-08 01:23:33 字數 1046 閱讀 6895

#include#include#include#include#includeusing namespace std;

typedef struct node

node,*plinklist;

plinklist createfromhead()

node *pstnode = (node *)malloc(sizeof(node));

pstnode->m_pnext = l->m_pnext;

pstnode->m_idata = _in;

l->m_pnext = pstnode;

}return l;

}void printlist(plinklist l)

node *p = l->m_pnext;

while(null != p)

coutnode *r = l;

bool bcontinue = true;

while(bcontinue)

node *s = (node *)malloc(sizeof(node));

s->m_idata = _in;

s->m_pnext = null;

r->m_pnext = s;

r = r->m_pnext;

}return l;

}plinklist insnode(plinklist l)

if(null == p || i != ipos)

plinklist delnode(plinklist l)

int ipos;

cout <<"please input the poszition :";

cin >>ipos;

int i = 0;

node *p = l;

while(i++ < ipos - 1 && null != p->m_pnext)

if(null == p->m_pnext || i != ipos )

int main()

}return 0;

}

單鏈表基本操作

單鏈表的初始化,建立,插入,查詢,刪除。author wang yong date 2010.8.19 include include typedef int elemtype 定義結點型別 typedef struct node node,linkedlist 單鏈表的初始化 linkedlist...

單鏈表基本操作

include using namespace std define namelenth 20 define ok 0 define error 1 typedef struct flagnode node 生成結點 inline node newnode 銷毀化煉表 void destroylin...

單鏈表基本操作

主要是單鏈表的一些常見操作 像建立鍊錶,刪除結點,插入結點,鍊錶逆序,按大小排序等 1 include 2 using namespace std 34 struct node59 10 11 建立帶有頭結點的單鏈表 12void create node head 1327 28 29 獲得鍊錶長度...