單鏈表相關演算法

2021-06-07 03:12:12 字數 767 閱讀 8272

#include

#include

using namespace std;

typedef int elemtype;

typedef struct node

nodetype;

nodetype *create()

s->next=null;

return head;

}void dis(nodetype *head)

while(p!=null)

cout<

int len(nodetype *head)

return j;

}nodetype *ins(nodetype *head,int i,elemtype x)

nodetype *p,*s,*t;

p=(nodetype *)malloc(sizeof(nodetype));

p->data=x;

t=head->next;

s=head;

int j=1;

while(j<=i)

p->next=s;

t->next=p;

return head;

nodetype *del(nodetype *head,int i)

int j=1;

nodetype *p,*s;

p=head->next;

s=head;

while(j

s->next=p->next;

return head;}

單鏈表相關操作

這是自己寫的最長的一次 了 在機房敲了一天。以前一直用list來水鍊錶的題 這次終於體會到痛苦了 include include include include include include using namespace std typedef struct node 單鏈表 s,list vo...

單鏈表相關操作

typedef int sltdatatype typedef struct slistnode slistnode typedef struct slist slist 通過畫圖來理解無頭單向非迴圈鍊錶的相關操作 其中操作在圖中用簡易偽 描述 先將要插入的結點指向第乙個結點,然後頭指標指向插入的結...

單鏈表相關習題

設定乙個臨時變數來當作計數器。然後對整個鍊錶進行遍歷來數出有效節點的個數。public intgetlength length temp temp.next return length 也可以直接使用whil來判斷進行條件。public intgetlength return length 解決這個...