#include<iostream>
using namespace std;
typedef struct Xu
{
string key;
int n;
}Xu;
typedef struct LNode {
Xu date;
struct LNode *next;
}LNode,*LinkList;
void InitList(LinkList &L)
{
string a[11] = { "xu1","xu2","xu3","xu4","xu5","xu6","xu7","xu8","xu9","xu10","xu11" };
int b[11] = { 39,90,37,50,35,28,6,0,12,23,78 };
L = new LNode;
L->next = NULL;
LNode *r = L;
for (int i = 0;i < 11;i++)
{
LinkList p = new LNode;
p->date.key = a[i];
p->date.n = b[i];
p->next = NULL;
r->next = p;
r = p;
}
}
void trvaseList (LinkList &L)
{
LinkList p;
p=L->next;
while(p)
{
cout <<p->date.key<<" "<<p->date.n << endl;
p=p->next;
}
system("pause");
}
void SearchList(LinkList &L,int n)
{
LNode *r = L->next;
int flag = 1;
while (r != NULL)
{
if (r->date.n == n) {
cout << "该记录为: " << r->date.key << " " << r->date.n << " " << "在表中位置为; " << flag << endl;
break;
}
else {
r = r->next;
flag++;
}
}
if (r == NULL)
cout << "该记录不存在" << endl;
}
int main()
{
LinkList L;
InitList(L);
trvaseList (L);
int n;
while(1)
{
cout << "输入您想要查找的数据" << endl;
cin >> n;
SearchList(L,n);
system("pause");
}
}
|