【数据结构(严蔚敏)】 线性表基本操作C语言实现(单链表)
vs2017
算法2.8–算法2.11
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASLBLE -1
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<<" ";
}
}
Status GetElem_L(Linklist L, int i, ElemType &e) {
//算法2.8
//L为带头节点的单链表头指正
//当第i个元素存在时,其值赋给e,返回OK,否则返回ERROR
Linklist p;
p = L