# 笔试题六：链表的顺序查找 并输出

struct ListNode

{

int data;

ListNode * nextNode;

}

int sequential_search(const List<int> &the_list,
const Key &target)
/*Post: If an entry in the_list is equal to target, then return the position
of this entry.
Otherwise return -1
*/
{
int position;
int s=the_list.size();
for(position=0;position<s;position++){
int data;
the_list.retrieve(position,data);
if(data==target){
return position;
}
}
return -1;
}

#include "stdafx.h"
#include<iostream>
#include<queue>
using namespace std;

typedef struct node{
int data;
struct node *next;
}Node,*List;

List createList(int N)
{
int count = 0;
while(count<N)
{	count++;
List s = (List)malloc(sizeof(Node));
s->data = count;
s->next = NULL;
p->next = s;
p = s;
}
}

{
{
return;
}
while(p)
{
cout<<p->data<<" ";
p = p->next;
}
cout<<endl;
}
{
int count = 0;
List second = NULL;
while(first&&count<index)//first首先找到第index个元素
{
first = first->next;
count++;
}
//cout<<"count: "<<first->data<<endl;
if(first!=NULL)//如果没有到链表尾
{
while(first!=NULL)
{
first = first->next;
second = second->next;
}
}
return second;
}
int main()
{
int N = 20;
if(no!=NULL)
{
cout<<no->data<<endl;
}else{
cout<<"can't find"<<endl;
}
getchar();
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：笔试题六：链表的顺序查找 并输出 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)