#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int status;
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;//结构体指针
}LNode,*LinkList;//同一结构体指针的两个名字
//初始化
status InitList(LinkList &L){
L=(LNode *)malloc(sizeof(LNode)); //生成新指针作为新结点,头指针指向头结点
L->next=NULL;//头结点的指针域为空
cout<<"创建链表成功!"<<endl;
return OK;
}
//取值
//取第i位元素的值e
status GetElem(LinkList L,int i,int &e){
LNode *p;
int j=1;
p=L->next;
while(p&&j<i){
p=p->next;
++j;
}
if(!p||j>i){
return ERROR;
}
e=p->data;
cout<<"查找元素["<<i<<":"<<e<<"]"<<endl;
return OK;
}
//查找
LNode *LocateElem(LinkList L,int e){
LNode *p;
p=L->next;
//顺链向后扫描知道p为空或是p所指结点的值为e
while(p&&p->data!=e){
p=p->next;
}
//查找成功返回值为e的结点,查找失败p为NULL
if(p){
cout
#include<iostream>
#include<stdlib.h>
#include<conio.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int status;
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;//结构体指针
}LNode,*LinkList;//同一结构体指针的两个名字
//初始化
status InitList(LinkList &L){
L=(LNode *)malloc(sizeof(LNode)); //生成新指针作为新结点,头指针指向头结点
L->next=NULL;//头结点的指针域为空
cout<<"创建链表成功!"<<endl;
return OK;
}
//取值
//取第i位元素的值e
status GetElem(LinkList L,int i,int &e){
LNode *p;
int j=1;
p=L->next;
while(p&&j<i){
p=p->next;
++j;
}
if(!p||j>i){
return ERROR;
}
e=p->data;
cout<<"查找元素["<<i<<":"<<e<<"]"<<endl;
return OK;
}
//查找
LNode *LocateElem(LinkList L,int e){
LNode *p;
p=L->next;
//顺链向后扫描知道p为空或是p所指结点的值为e
while(p&&p->data!=e){
p=p->next;
}
//查找成功返回值为e的结点,查找失败p为NULL
if(p){
cout