![順序表實驗報告_第1頁](http://file4.renrendoc.com/view/56f5ed2f51faf977a591defd6daf5c11/56f5ed2f51faf977a591defd6daf5c111.gif)
![順序表實驗報告_第2頁](http://file4.renrendoc.com/view/56f5ed2f51faf977a591defd6daf5c11/56f5ed2f51faf977a591defd6daf5c112.gif)
![順序表實驗報告_第3頁](http://file4.renrendoc.com/view/56f5ed2f51faf977a591defd6daf5c11/56f5ed2f51faf977a591defd6daf5c113.gif)
![順序表實驗報告_第4頁](http://file4.renrendoc.com/view/56f5ed2f51faf977a591defd6daf5c11/56f5ed2f51faf977a591defd6daf5c114.gif)
![順序表實驗報告_第5頁](http://file4.renrendoc.com/view/56f5ed2f51faf977a591defd6daf5c11/56f5ed2f51faf977a591defd6daf5c115.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
順序表實驗報告一、實驗?zāi)康恼莆站€性表的順序表表示及其基本操作的實現(xiàn)算法;掌握利用順序表解決問題的方法。二、實驗內(nèi)容(1)編寫代碼實現(xiàn)順序表的類型定義及順序表的初始化、插入、刪除、取元素、輸出等操作;(2)應(yīng)用所實現(xiàn)的順序表,從以下所列問題中至少選其一(當(dāng)然,兩個都寫分?jǐn)?shù)肯定會更高哦?。┻M(jìn)行求解:①設(shè)計并實現(xiàn)集合的表示集合的創(chuàng)建、輸出、并集運算、交集運算等操作;②設(shè)計并實現(xiàn)一個簡單的學(xué)生信息管理(包括信息錄入、顯示、查找、插入、刪除等操作);(3)針對所選擇的求解問題,編寫測試程序,并選取適當(dāng)?shù)臏y試數(shù)據(jù),通過運行結(jié)果驗證算法和程序設(shè)計的正確性。三、實驗過程1.順序表的實現(xiàn)這里的內(nèi)容是用C語言去實現(xiàn)順序表及其的基本操作,也是實驗的核心部分,希望學(xué)弟學(xué)妹們可以好好體會,代碼我就不給出了。下面的問題我會使用C++的vector容器來實現(xiàn),本質(zhì)上此部分內(nèi)容就是在寫一個簡單的vector,這也就是為什么C++是C語言的補(bǔ)充。大家在做實驗的時候只需參考一下我的解法,并把vector換成自己實現(xiàn)的順序表就可以,記得加上運行結(jié)果或結(jié)果截圖,我就不一一給出結(jié)果。對C++的vector源碼感興趣的同學(xué)可以看一看《STL源碼剖析》。2.集合問題#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
usingnamespacestd;
typedefvector<int>ArrayList;
voidcreateArrayList(ArrayList&A,intsize);//創(chuàng)建集合
voidoutputArrayList(ArrayListA);//輸出集合
voidArrayListUnion(ArrayListA,ArrayListB,ArrayList&C);//求并集
voidArrayListIntersection(ArrayListA,ArrayListB,ArrayList&C);//求交集
voidArrayListSubtraction(ArrayList&A,ArrayListB,ArrayList&C);//求差集
intmain()
{
ArrayListA,B,C;
//創(chuàng)建集合A,B
intA_size,B_size;
printf("創(chuàng)建SectionA:\n");
printf("\t\t元素個數(shù):");
scanf("%d",&A_size);
createArrayList(A,A_size);
printf("創(chuàng)建SectionB:\n");
printf("\t\t元素個數(shù):");
scanf("%d",&B_size);
createArrayList(B,B_size);
//輸出
printf("SectionA=");
outputArrayList(A);
printf("\n");
printf("SectionB=");
outputArrayList(B);
printf("\n");
//求C=A∪B
ArrayListUnion(A,B,C);
printf("A∪B=");
outputArrayList(C);
printf("\n");
//清空C
C.clear();
//求C=A∩B
ArrayListIntersection(A,B,C);
printf("A∩B=");
outputArrayList(C);
printf("\n");
//求C=A-B
ArrayListSubtraction(A,B,C);
printf("A-B=");
outputArrayList(A);
return0;
}
//創(chuàng)建集合
voidcreateArrayList(ArrayList&A,intsize)
{
printf("\t\t請輸入%d個元素:",size);
for(inti=0;i<size;i++)
{
inte;
scanf("%d",&e);
A.push_back(e);
}
}
//輸出集合
voidoutputArrayList(ArrayListA)
{
printf("{");
for(inti=0;i<A.size();i++)
{
if(i==A.size()-1)printf("%d",A[i]);
elseprintf("%d,",A[i]);
}
printf("}\n");
}
//求并集
voidArrayListUnion(ArrayListA,ArrayListB,ArrayList&C)
{
//復(fù)制A集合
for(inti=0;i<A.size();i++)
C.push_back(A[i]);
for(inti=0;i<B.size();i++)
{
ArrayList::iteratorit=find(A.begin(),A.end(),B[i]);
if(it==A.end())C.push_back(B[i]);
}
}
//求交集
voidArrayListIntersection(ArrayListA,ArrayListB,ArrayList&C)
{
for(inti;i<B.size();i++)
{
ArrayList::iteratorit=find(A.begin(),A.end(),B[i]);
if(it!=A.end())C.push_back(B[i]);
}
}
//求差集
voidArrayListSubtraction(ArrayList&A,ArrayListB,ArrayList&C)
{
inti;
for(inti=0;i<C.size();i++)
{
ArrayList::iteratorit=find(A.begin(),A.end(),C[i]);
if(it!=A.end())A.erase(it);
}
}3.學(xué)生信息管理#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<algorithm>
usingnamespacestd;
#defineMAX20
typedefstructstudent{
charname[MAX];
charsex[4];
intage;
charbirth[MAX];
}Student;
typedefvector<Student>Students;
boolequal(Student*a,Student*b);//判斷元素是否相等
voidinterface();//界面
voidaddStudent(Students&stus);//增加學(xué)生
voiddetStudent(Students&stus,charname[MAX]);//刪除學(xué)生
voidmodifyStudent(Students&stus,charname[MAX]);//修改學(xué)生
voidviewStudent(Students&stus);//查看學(xué)生
voidsortStudent(Students&stus);//排序
intmain()
{
intchoice=0,n=0;
Studentsstus;
while(1)
{
system("cls");
interface();
printf("請輸入功能編號:");
scanf("%d",&choice);
switch(choice)
{
case1://查看
system("cls");
viewStudent(stus);
system("pause");
break;
case2://增加
system("cls");
addStudent(stus);
system("pause");
break;
case3://刪除
system("cls");
charname1[MAX];
printf("請輸入要刪除的學(xué)生的姓名:");
scanf("%s",name1);
detStudent(stus,name1);
system("pause");
break;
case4://修改
system("cls");
charname2[MAX];
printf("請輸入要修改的學(xué)生的姓名:");
scanf("%s",name2);
modifyStudent(stus,name2);
system("pause");
break;
case5://排序
system("cls");
sortStudent(stus);
printf("編排成功");
system("pause");
break;
default://退出
exit(0);
}
}
return0;
}
boolequal(Studenta,Studentb)
{
if(!strcmp(,))
returntrue;
else
returnfalse;
}
//界面
voidinterface()
{
printf("-----------學(xué)生信息管理系統(tǒng)-----------\n");
printf("1.查看學(xué)生信息\n");
printf("2.增加學(xué)生信息\n");
printf("3.刪除學(xué)生信息\n");
printf("4.修改學(xué)生信息\n");
printf("5.編排學(xué)生信息\n");
printf("6.退出管理系統(tǒng)\n");
printf("--------------------------------------\n");
}
//增加
voidaddStudent(Students&stus)
{
printf("請輸入該學(xué)生的姓名,性別,年齡和出生日期:\n");
Students;
scanf("%s",);
scanf("%s",s.sex);
scanf("%d",&s.age);
scanf("%s",s.birth);
stus.push_back(s);
}
//刪除
voiddetStudent(Students&stus,charname[MAX])
{
Students;
strcpy(,name);
Students::iteratorit;
for(it=stus.begin();it!=stus.end();it++)
if(equal(*it,s))
{
stus.erase(it);
return;
}
printf("刪除錯誤:不存在此人!\n");
}
//修改
voidmodifyStudent(Students&stus,charname[MAX])
{
students;
strcpy(,name);
Students::iteratorit=stus.begin();
for(it=stus.begin();it!=stus.end();it++)
if(equal(*it,s))
{
printf("請修改該名學(xué)生的姓名,性別,年齡和出生日期:\n");
scanf("%s%s%d%s",(*it).name,(*it).sex,&(*it).age,(*it).birth);
return;
}
printf("修改錯誤:不存在此人!\n");
}
//查看
voidviewS
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 蘇科版數(shù)學(xué)八年級下冊《9.5 三角形的中位線》聽評課記錄
- 青島版數(shù)學(xué)八年級上冊2.6《等腰三角形》聽評課記錄2
- 湘教版數(shù)學(xué)八年級上冊1.4《分式的加法和減法》聽評課記錄6
- 2025年金屬冶煉加工合作協(xié)議書
- 小學(xué)二年級數(shù)學(xué)口算訓(xùn)練題
- 幼兒籃球周末培訓(xùn)班合作協(xié)議書范本
- 外貿(mào)公司用工勞動合同范本
- 租賃安全協(xié)議書范本
- 二零二五年度智慧城市軟件外包合作協(xié)議
- 2025年度雞蛋電商平臺合作協(xié)議模板帶數(shù)據(jù)共享與平臺運營
- 我的消防文員職業(yè)規(guī)劃
- 人教PEP版2025年春季小學(xué)英語三年級下冊教學(xué)計劃
- 2025年公司品質(zhì)部部門工作計劃
- 2024年世界職業(yè)院校技能大賽高職組“市政管線(道)數(shù)字化施工組”賽項考試題庫
- 華為研發(fā)部門績效考核制度及方案
- CSC資助出國博士聯(lián)合培養(yǎng)研修計劃英文-research-plan
- 《環(huán)境管理學(xué)》教案
- 2025年蛇年年度營銷日歷營銷建議【2025營銷日歷】
- (一模)寧波市2024學(xué)年第一學(xué)期高考模擬考試 數(shù)學(xué)試卷(含答案)
- 攝影入門課程-攝影基礎(chǔ)與技巧全面解析
- 冀少版小學(xué)二年級下冊音樂教案
評論
0/150
提交評論