main.cpp
来自「查找链表中倒数第M个元素 其中包含链表原码」· C++ 代码 · 共 24 行
CPP
24 行
#include "LList.h"
#include <iostream>
using namespace std;
int main()
{
int i;
int m,n;
int value;
LList <int> llist; //the template contain element's type is int
for(i=1;i<=1000;i++)
{
llist.append(i);
}
n = llist.rightLength(); //get the number of totol elements
do{
cout << "please input a integer between 1 and "<< n <<endl;
cin >> m; //imput m
}while (m<1||m>n);
llist.setPos(n-m); //get the last No.m fence
llist.getValue(value);
cout <<"the last No."<<m<<" element is " <<value<<endl; //output the last No.m nubmer
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?