搜索
您的当前位置:首页正文

约瑟夫环实验报告

来源:意榕旅游网


算法与数据结构实验报告——实验三

实验名称 约瑟夫问题 姓 名 %% 实验 地点 实验目的 设计流程 实 验 内 容 与

成绩 学号 %% && 班级 && 指导教师 完成 日期 )) (( 1.熟练掌握线性表的基本操作(建立、插入、删除、遍历等)在链式存储结构上得实现。 2.学会单向循环链表的运用。 3.掌握在各种链表结构中实现线性表操作的基本方法,能在实际应用中选择适当的链表结构。 数据类型定义: typedef struct node //定义单链表结点结构 { int data; struct node *next; }LNode; LNode* Create(int n,int k);//创建循环链表// LNode* GetNode(LNode *); //将那个出列的结点假意删除 int Print(LNode *,int); //打印出那些出表的顺序结点 1) 检查所用的计算机系统是否已安装了C编译错误分析 系统并确定它所在的子目录; 2) 进行所用的集成环境; 3) 熟悉集成环境的界面的有关菜单的使用方法; 4) 建立“顺序表的操作”工程。 the console application. // #include \"stdafx.h\" #include #include typedef struct node //定义单链表结点结构 { E:\\程序\\约瑟夫_project\\约瑟夫_project.cpp(38) : error C2065: 'p' : undeclared identifier E:\\程序\\约瑟夫_project\\约瑟C2440: '=' : cannot convert from 'struct node *' to 'int' This a C-style conversion cast or requires a reinterpret_cast, function-style cast Error executing cl.exe. 约瑟夫_project.exe - 2 // 约瑟夫_project.cpp : Defines the entry point for 夫_project.cpp(38) : error

步 骤 实 验 内 容 与 步 骤 int data; struct node *next; error(s), 0 warning(s) 解决:1.首先是在main()函数中p未定义,定义下即可 2.第二个主要是因为在函数调用时未注意形参类型。修改后调试正确。 }LNode; int main() { } LNode* Create(int n,int k)//创建循环链表// { int start=k-1; LNode *s,*p,*L=0,*t; if (start==0) start=n; while (n!=0) LNode* Create(int n,int k);//创建循环链表// LNode* GetNode(LNode *); //将那个出列int Print(LNode *,int); //打印出那些出表LNode *p; int n,k,m; do { } while (n<=0); do { } while (k<=0 || k>n); do { } while(m<=0); Print(p,m); return 0; printf (\"输入报数上限值\"); scanf (\"%d\printf (\"输入开始人的序号(1~%d)\scanf (\"%d\printf (\"输入总人数\"); scanf (\"%d\的结点假意删除 的顺序结点 p=Create(n,k);

} { } p->next=L; return t; s=(LNode *)malloc(sizeof(LNode)); if (L==0) p=s; if (n==start) t=s; s->data=n; s->next=L; L=s; n--; LNode* GetNode(LNode *p)//出队函数相当于将将出列的那个数筛除出单链表// { } int Print(LNode *p,int m)//打印出列顺序的函数// { 实验心得

LNode *q; for (q=p;q->next!=p;q=q->next); q->next=p->next; free (p); return (q); int i; printf (\"出队编号:\\n\"); while (p->next!=p) { } printf(\"%d\\n\return 0; for (i=1;i<=m;i++) p=p->next; printf (\"%d \p=GetNode(p); } 1.设计链式结构存储时,注意该结构结点的位置和作用域; 2.注意头文件的添加,以及中英文的切换; 3.注意变量用的时候注意是否定义,以及变量名的大小写区分。

因篇幅问题不能全部显示,请点此查看更多更全内容

Top