文档介绍:#include <cstdlib>
#include <iostream>
using namespace std;
typedef struct Lnode
{
int data;
struct Lnode *next;
}LNode;
int Get_i(LNode *L)
{
cout<<"输入查找的是第几个元素";
int a,i=1;
LNode *k=L;
cin>>a;
while(i<=a&&k->next!=NULL)
{
i++;
k=k->next;
}
cout<<"第"<<a<<"个元素是"<<k->data<<endl;
}
int Get_value(LNode *L)
{
cout<<"输入查找元素的值是:";
int count=1,x;
LNode *k=L;
cin>>x;
while(k->next->data!=x&&k->next!=NULL)
{
count++;
k=k->next;
}
cout<<"所查找的元素"<<x<<"是第"<<count<<"个"<<endl;
}
void Insert(LNode *L)
{
cout<<"输入需要插入数据的位置:";
int i,j=1,k; //i是插入的位置,k是插入的数据
LNode *p,*q,*r;
r=L;
p=L;
cin>>i;
cout<<" "<<"需要插入的数据是:";
cin>>k;
while(j<i)
{
p=p->next;
j++;
}
q=(LNode*)malloc(sizeof(LNode));
q->data=k;
q->next=p->next;
p->next=q;
cout<<"现在的链表中数据是"<<endl;
while(r->next!=NULL)
{
cout<<r->next->data<<" ";
r=r->next;
}
}
void Delete_i(LNode *L)
{
cout<<"输入需要删除数据的位置:";
int i,j=0;
cin>>i;
LNode *p=L,*q,*r;
r=L;
while(j<i)
{
j++;
q=p;
p=p->next;
}
q->next=p->next;
free(p);
cout<<"现在的链表中数据是"<<endl;
while(r->next!=NULL)
{
cout<<r->next->data<<" ";
r=r->next;
}
cout<<endl;
}
void Delete_value(LNode *L)
{
cout<<"输入需要删除数据的值:";
int x;
cin>>x;
LNode *p=L,*q,*r=L;
while(p->next->data!=x)
{
q=p;
p=p->next;
}
q=p;
p=p->next;
q->next=p->next;
free(p);
cout<<"现在的链表中数据是"<<endl;
while(r->next!=NULL)
{
cout<<