题目:
分析:09年的链表题目比较简单,直接构建链表,然后根据不同思路模拟即可。
思路一:循环遍历
思考:最容易想到的思路,直接暴力循环。偷了一下懒,变量名称没用题目的,考试写的时候不能错。写了完整的运行代码,考试的时候看题目要求写上链表定义,实现函数即可。
#include <iostream>
using namespace std;
typedef struct Node
{
int data;
struct Node* next;
//数据域整型,指向空
}node,*list;//单个节点,链表指针
int create(list &L)
{
int n;
node*t,*r;//临时指针和尾指针
r=L;
cin>>n;
for(int i=0;i<n;i++)
{
t=new node;
cin>>(t->data);
t->next=NULL;
r->next=t;
r=t;
}
}
void print(list L)
{
node*t;
t=L->next;
while(t!=NULL)
{
cout<<t->data<<' ';
t=t->next;
}
}
int check(list L)
{
int k;
cin>>k;
int cnt=0;