From fd842609c2a53fcc4aa5f3c60804a61637a8ee83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E6=98=B4?= Date: Sun, 22 Dec 2024 00:43:10 +0800 Subject: [PATCH] test1 --- homework6/CMakeLists.txt | 6 ++++++ homework6/test1.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 homework6/CMakeLists.txt create mode 100644 homework6/test1.cpp diff --git a/homework6/CMakeLists.txt b/homework6/CMakeLists.txt new file mode 100644 index 0000000..9e5e6ee --- /dev/null +++ b/homework6/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.30) +project(homework6) + +set(CMAKE_CXX_STANDARD 20) + +add_executable(test1 test1.cpp) diff --git a/homework6/test1.cpp b/homework6/test1.cpp new file mode 100644 index 0000000..3bed782 --- /dev/null +++ b/homework6/test1.cpp @@ -0,0 +1,38 @@ +// 编写一个程序,输出在顺序表(3,6,2,10,l,8,5,7,4,9) 中采用顺序查找方法查找关键字5的过程。 +#include +#include + +using namespace std; + +template +int seqSearch(list l,T value) { + if (l.empty()) { + cout << "空表" << endl; + return -1; + } + bool found = false; + int index = 0; + for (typename list::iterator it = l.begin(); it != l.end(); ++it) { + cout<<"正在顺序查找第"< l={3,6,2,10,'l',8,5,7,4,9}; + int index=seqSearch(l,5); + cout<