- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
大家好,我找不到错误。这是我的代码:
#include <iostream>
using namespace std;
int a[20], n, lb, loc, ub, left, right, temp, temp1;
void quicksort(int[10],int,int);
int pivot(int[],int,int);
void merge(int *,int, int , int );
void mergesort(int *a, int low, int high)
{
int mid;
if (low < high)
{
mid=(low+high)/2;
mergesort(a,low,mid);
mergesort(a,mid+1,high);
merge(a,low,high,mid);
}
return;
}
void merge(int *a, int low, int high, int mid)
{
int i, j, k, c[50];
i = low;
k = low;
j = mid + 1;
while (i <= mid && j <= high)
{
if (a[i] < a[j])
{
c[k] = a[i];
k++;
i++;
}
else
{
c[k] = a[j];
k++;
j++;
}
}
while (i <= mid)
{
c[k] = a[i];
k++;
i++;
}
while (j <= high)
{
c[k] = a[j];
k++;
j++;
}
for (i = low; i < k; i++)
{
a[i] = c[i];
}
}
int main()
{
int opt;
cout << "QuickSort & MergeSort Toolbox: " << endl;
do
{
int opt;
cout << "1. MergeSort" << endl;
cout << "2. QuickSort" << endl;
cout << "enter option: ";
cin >> opt;
switch(opt)
{
case 1:
{
cout << "MERGE SORT" << endl;
int a[20], i, b[20];
cout<<"Enter the elements\n";
for (i = 0; i < 5; i++)
{
cin>>a[i];
}
mergesort(a, 0, 4);
cout<<"Sorted array\n";
for (i = 0; i < 5; i++)
{
cout<<a[i];
}
cout<<"Enter the elements\n";
for (i = 0; i < 5; i++)
{
cin>>b[i];
}
mergesort(b, 0, 4);
cout<<"Sorted array\n";
for (i = 0; i < 5; i++)
{
cout<<b[i];
}
}
case 2:
{
cout<<"Enter size of array";
cin>>n;
cout<<"Enter Array Elements ";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
quicksort(a,0,n-1);
for(int z=0;z<n;z++)
{
cout<<" "<<a[z];
}
return 0;
}
default:
{
cout << "Invalid Input" << endl;
}
}
}while(opt != -1);
void quicksort(int a[], int lb, int ub)
{
int p;
if(lb<ub)
{
p=pivot(a,lb,ub);
quicksort(a,lb,p-1);
quicksort(a,p+1,ub);
}
}
int pivot( int a[],int lb,int ub )
{
for(int z=0;z<n;z++)
{
cout<<" "<<a[z];
}
cout<<endl;
left =lb;
right = ub;
loc =lb;
cout<<"Right Side is:- "<<right;
cout<<"\tLocation is:-"<<loc;
cout<<"Left Side is:- "<<left;
cout<<"Now Right Side is: \n";
while((a[loc]<=a[right]) && (loc!=right))
{
right=right-1;
}
if(loc==right)
{
return loc;
}
temp=a[loc];
a[loc]=a[right];
a[right]=temp;
loc=right;
cout<<"Now Left Side is: \n";
while((a[left]<=a[loc]) && (loc!=left))
{
left=left+1;
}
if(loc==left)
{
return loc;
}
temp1=a[loc];
a[loc]=a[left];
a[left]=temp1;
loc=left;
}
我想更正那个错误,但我能找到它。非常欢迎任何帮助或提示。终端显示这是一个遗漏的括号,但我看到了所有括号。
最佳答案
在此处在线缩进您的代码。然后,正如编译器所说,转到第 131 行并注意 main 没有右大括号。添加一个,例如这样:
...
}while(opt != -1);
return 0;
}
这将解决这个问题,但代码也会出现其他错误,但我会把有趣的部分留给你。
我有一个 Quicksort (C++) 的例子,这可能会派上用场。
关于c++ - 合并排序和快速排序 C++ 的工具箱(有错误的代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37116814/
我正在编写一个 T4 脚本,它反射(reflect)了某些类并提供基于它们的代码生成。问题是我的脚本出错了,说我当前项目中的类无法访问。 脚本本身与我试图引用的类位于同一个程序集中。我试过引用命名空间
我在运行 Docker Toolbox v. 1.13.1a在 Windows 7 Pro Service pack 1 x64操作系统。 与 Virtual Box Version 5.1.14 r
我正在尝试使用 t4toolbox 为项目生成 linq2sql 类。已经有很多针对默认 dbml 生成的代码编写的代码。 在 LinqToSqlEntityClassTemplate.tt 文件中有
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我拥有 MATLAB R2016b 和 Parallel Toolbox 的独立许可证。我正在编写一个应用程序,将发送给可能没有安装该工具箱的客户,我想编写我的应用程序以使其正常失败(即运行单线程)。
R2014b 中新增的工具箱打包功能看起来很不错。 但是,您似乎只能通过工具箱打包 GUI 来打包工具箱。 我希望能够创建一个 .prj使用 GUI 交互式文件,然后使用此 .prj 以编程方式打包工
我必须重新投影我的 3D 点(我已经有来自 Bundler 的数据)。 我在 MATLAB 中使用相机校准工具箱来获取相机的固有参数。我从 27 张图像中得到了这样的输出(棋盘;图像是从不同角度拍摄的
我将我的 boot2docker 更新为 DockerToolbox。 现在我尝试使用 Sequal Pro(MySQL 客户端)连接到我的数据库,但我的 ssh 登录到我的 VM 失败,并使用以下用
所以我使用 Docker Toolbox 是因为我的机器上没有 Hyper-V,因为它不是 Windows 10 专业版。一切似乎都很好,但是当我尝试在我的浏览器 0.0.0.0:80 上继续时,它总
我是 T4 新手,正在尝试使用 T4 Toolbox基于 this answer 生成 F# 代码,但似乎类功能块不能与语句块混合。这是我的代码: module Module2 我收
我正在使用 SOM Toolbox分析从汽车数据库收集的数据。我的问题是在可视化统一距离矩阵时。引用 som_umat 的文档: Compute and return the unified dist
我正在为我们编写的自定义 SSIS 组件创建安装程序。我想自动添加自定义组件,而不是要求用户手动添加它。 我正在尝试用这段代码来做到这一点: public void AddToolboxItem(st
我使用的是 Win7 和 DockerToolbox 18.03。我在运行卷时遇到了一些问题,所以我开始尝试使用 Kitematic: 我从 mysql 运行一个容器,在选项“volumes”中我看到
我在我的 jQuery 移动应用程序上创建侧边栏工具箱时遇到困难。 我想要这样的渲染:http://www.paultrifa.com/envato/themeforest/side/red/prev
我正在尝试学习 HMM GMM 实现并创建了一个简单的模型来检测某些特定的声音(动物叫声等) 我正在尝试在 MATLAB 中使用 GMM(高斯混合)训练 HMM(隐马尔可夫模型)网络。 我有几个问题,
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
如何在脚本/函数中检查已安装的 MATLAB 工具箱? (检查工具箱版本也很好!)当有人试图在没有所需工具箱的情况下运行脚本时,这可以提供快速且有用的错误消息。 想到的一个快速但粗略的解决方案是解析
我在 Mac 上使用 Docker Toolbox。 docker push 挂起。我如何硬重启守护进程或 docker-machine VM 以使这个以一种不好的方式解除挂起。等待的时间太长了。 最
我使用 apt-get 安装了 Scilab,现在我想安装这个工具箱:http://sourceforge.net/projects/data-comm/ 我试过这个: tomsInstall('/h
编辑:问题是 COMPOSE_CONVERT_WINDOWS_PATHS环境变量没有设置。我尝试将它添加到 Dockerfile和 .env文件,但它没有被设置。我无法设置任何新的环境变量。它就像从缓
我是一名优秀的程序员,十分优秀!