1、Void menu()Bool DelLinkList(LinkList &L,int pos,int &e)5. 调试分析-Configuration: 33 - Win32 Debug-Compiling.11.cppD:AA3311.cpp(6) : error C2146: syntax error : missing ; before identifier data error C2501: ElemType : missing storage-class or type specifiersAA3311.cpp(12) : error C2061: identifier AA331
2、1.cpp(13) :delect_L fatal error C1004: unexpected end of file foundError executing cl.exe.33.exe - 7 error(s), 0 warning(s)6. 使用说明程序名为LinkList.exe,运行环境为DOS。程序执行后显示:2-DELETEPlease Select(2):在Please Select(2):后输入数字选择执行不同的功能。每执行一次功能,就会显示执行的结果(正确或错误)以及执行后单链表的内容。选择2:显示DELETE pos,e=,要求输入要删除的位置,执行成功后返回元素的值
3、。7. 测试结果#includestdlib.hmath.htypedef int Elemtype;typedef struct LNode;ElemType data;struct LNode *next;LNode;LNode *L;LNode *creat_L();void out_L(LNode *L);void insert_L(LNode *L,int i,ElemType e);ElemType delect_L(LNode *L,int i);int locat_L(LNode *L,ElemType e);void main()int i,k,loc;ElemType e,
4、x;char ch;do printf(n); printf(n 1.建立单链表n 2.删除元素n 3.结束程序运行n=n 请输入您的选择(1,2,3) scanf(%d,&k); switch(k) case1:L=creat_L(); out_L(L); break;case2:printf(n请输入要删除元素的位置:i); x=delete_L(L,i); if(x!=-1)printf(n删除的元素为:%dn,x);删除%d后的单链表为: else printf(n要删除的元素不存在! LNode *creat_L() LNode *h,*p,*s; ElemType x; h=(LN
5、ode *)malloc(sizeof(LNode); h-next=NULL; p=h;n请输入第一个数据元素:x); while(x!=-999) s=(LNode *)malloc(sizeof(LNode); s-data=x; p-next=s; p=s;请输入下一个数据:(输入-999表示结束.) return(h); /*creat_L */ void out_L(LNode *L) LNode *p; p=L-next;nn while(p!=NULL) printf(%5d,p-data);p=p- ; /*out_link*/ Elemtype delete_L(LNode
6、 *L,int i) LNode *p,*q;int j;ElemType x; p=L;j=0; while(p-next!=NULL&jj+; if(! p-next|ifree(q); return(x); / *delete_L */实验报告二设计一个程序,用于演示折半查找的查找方法,要求采用菜单的形式进行选择。本程序在TC2.0环境下编写程序,完成折半查找。执行查找操作时,需要输入待查找元素的值。查找操作完成后,若找到待查找元素,则显示该元素在线性表中的位置,反之,给出Cannot find!信息。完成线性表的查找操作。(1)为了实现上述程序功能,需要定义线性表的数据结构。 显示主界
7、面Menu() 查找表的初始化ElemInit() 显示静态查找主界面PrintStaticMenu() 折半查找BinarySearch 主函数main()(3)各函数间的关系如图所示。(1)查找表顺序存储结构和链式存储结构的定义 Typedef struct Keytype key;ElemType;Typedef struct ElemType elemMAX_LIST_LEN+1 Int length;Seq_Table;Seq_Table seqtbl;Typedef struct NODE ElemType elem;Struct NODE*next;LINK_NODE;(2)基本
8、操作。Typedef struct KeyType key; InfoType otherinfo; NodeType;Typedef NodeType Seqlistn+1; ZZ - Win32 Debug-XX.CPPd:aazzxx.cpp(1) : error C2018: unknown character 0xa10xb4 error C2006: #include expected a filename, found identifieraazzxx.cpp(7) : error C2143: before TypedefZZ.exe - 6 error(s), 0 warni
9、ng(s)每执行一次功能,就会显示执行的结果(正确或错误)以及执行后线性表的内容。选择1:静态查找。动态查找。选择0:退出。#includestdio.hconio.hstring.hmalloc.h#define Keytype int#define MAX_LIST_LEN100#define ENDVALUE -1Typedef struct BINNODE Struct BINNODE*lchild,*rchild;BSTNode,*BSTree;/*显示主页面*/Void PrintMenu() printf(nnnnnttt - 各类查找综合演示 - nnttt*nttt* 1-静
10、态查找 *nttt* 2-动态查找 * nttt* 0-退 出 *nttt*nttt请选择功能号(0-2):/*查找表初始化*/Void ElemInit() Int i=1; PrintfLIST_LEN,ENDVALUE); seqtbl.length=0;while(1)scanf(elem.key);if(elem.key= =ENDVALUE)break;else seqtbl.elemi+.key;seqtbl.length+;/*输出查找表的所有元素*/ void output(Seq_Table seqtbl1)int kprintffor(k=1;k=-32768&(x=32
11、767) printf break;return x;/*显示静态查找主界面*/Void PrintStaticMenu()ttt - 静态查找综合演示 - nnttt* 1-折半差找 *printf(nttt* 0-返回主界面 *nttt*nttt请选择功能号(1):Int BinarySearch(Seq_Table Seq_Tbl,Keytype Sea_Key)/*Seq_Tbl为查找表,Seq_Key为待查找的关键字*/int mid, low,high;low=1;high=Seq_Tbl.length;while(low=high) mid=(low+high)/2; if (S
12、eq_Tbl.elmemid.keySeq_Key) high=mid-1if(lowhigh) return 0 return mid;void StaticSearch() char static_func_choice; printStaticMenu(); getchar(); dtatic_func_choice=getchar(); while(static_fun_choice!=0) switch (static_func_choice) case1: int retval,seakey; seakey=input(); printf(n请注意!折半查找要求是有序表,若元素顺序
13、无序,则首先将排序! n BubbleSort(&seqtbl); retval=BinarySearch(seqtbl,seakey); output(seqtbl);nt你要查找的关键字为:,seakey); if(retval0) printf(nt查找成功,关键字为%d的元素位于第个%d位置!,seakey,retval); elsent对不起,关键字为%d的元素不存在.seakey); break; default: printf(n请输入正确的操作选项(1): getchar(); PrintStaticMenu();void DynamicSearch()Keytrpe Ins_
14、key,Sea_Key; BSTree p,root=NULL; char dynamic_func_choice; PrintDynamicMenu(); dynamic_fun_choice=getchar(); while (dynamic_func_choice! switch(dynamic_func_choice) casent请输入要查找的关键字: scanf(Sea_Key); SearchBST(root,Sea_Key); break; printDynamicMenu(); dynamic_func_choice=getchar(); char func_choice;
15、PrintMenu(); func_choice=getchar(); while (fun_choice! switch(func_choice) case StaticSearch(); break;2 DynamicSearch() func_choice= default: printf(实验报告三要求使用自己熟悉的的排序算法,将指定文件中的字符按行进行插入排序。(1)建立文件 建立一个文本文件IN.TXT,输入若干行字符串(文件中的数据可自拟),每个串以回车符结束。(2)算法输入 从文件IN.TET中按行读取字符并存入二维字符数组。(3)算法输出 将排序后的二维字符数组输出到另一个文
16、本文件OUT.TXT中。先将指定文本文件IN.TXT中的数据按行读入一个二维字符数组;然后对该二维字符数组中的字符按行执行直接插入排序和冒泡排序;最后将已排好序的数据按行写入另一个文本文件OUT.TET中。冒泡排序的基本思想是将n个记录看作按纵向排列,每趟排序时自下至上对每对相邻记录进行比较,若次序不符合要求(逆序)就交换。每趟排序结束时都能使排序范围内关键字最小的记录象一个气泡一样升到表上端的对应位置,整个排序过程共进行n-1趟,依次将关键字最小、次小、第三小的各个记录“冒到”表的第一个、第二个、第三个位置上(1)数据类型定义Char xx5080;(2)基本操作Void InsertSor
17、t(SeqList R)int i,j;For(i=2;i=n;i+)R0=Ri;J=i-1;While(R0.keyRj.key/*从右向左有序区R1.i-1中查找Ri的插入位置*/Rj+1=Rj;j-;Rj+1=R0;/*InsertSort*/(3)设文件IN.TXT中数据如下:ISAM enhances the functionality of your programs through itsFlexibility. If you add a section to a book,remove a few pafes,Or rearrange paragraphs or section
18、s,you have to recreate yourIndex,since the keywords must appear in relation to each other is Alphabetic order. A ISAM index changes automatian employee,or 慢慢 - Win32 Debug-解决.cppLinking.LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain16Debug/慢慢.exe : fatal error LNK1120: 1
19、 unresolved externalsError executing link.exe.慢慢.exe - 2 error(s), 0 warning(s)程序运行后文件OUT.TXT中的数据如下:AIMSaaacceeeffgghhhhiiilmnnnnoooooprrrrssstttttuuuyy,.Iaaaaabbcddeeeeeefffgiiiikllmnooooooprsstttuvwxyy,aaaaaaacceeeeeeegghhinnoooooopprrrrrrrrrssstttuuvyy,.aaaaccddeeeeeeeehhhiiiiklmnnnnoooopprrrrssstttt
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1