数据结构严蔚敏版类C的编码补全;
单链表的取值,删除,插入,合并。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef int Status;
typedef int ElemType;
typedef struct LNode { //单链表的存储结构
ElemType data;
struct LNode *next;
}LNode,*Linklist;
void Listshow(Linklist L) {
Linklist p;
p = L;
cout << "显示表L:"<<endl;
while (p->next) {
p = p->next;
cout << p->data<<" ";
}
}
void GetElem_L(Linklist L, int i) { //单链表的取值
//算法2.8
//L为带头节点的单链表头指正
//当第i个元素存在时,其值赋给e,
Linklist p;
p = L->next;
int j = 1;
while (p&&j < i) { //p为空时或者当P指向第i个元素时
p = p->next;
++j;
}
if (!p || j > i)
cout << "ERROR" << endl; //p为空表(说明i>n)和j>i(说明i<=0)
int e = p->data;
cout << "取值完成:" << e &