问题描述
基本上,即使这是一个 c++ 脚本而不是 python 脚本,anaconda 也会激活。 (请参阅附加图像中的输出)
输出:c:\Projects\C++ - Projects>conda activate tf [正如你所看到的,cout 在没有任何输入的情况下运行][1]
这对我来说有点烦人。 请看看是否有任何解决方案,我的猜测是 vscode 中的一些工作区设置导致了这种情况。 提前致谢。
#include <iostream>
using namespace std;
void swapping(int &a,int &b)
{ //swap the content of a and b
int temp;
temp = a;
a = b;
b = temp;
}
void display(int *array,int size)
{
for (int i = 0; i < size; i++)
cout << array[i] << " ";
cout << endl;
}
void bubbleSort(int *array,int size)
{
for (int i = 0; i < size; i++)
{
int swaps = 0; //flag to detect any swap is there or not
for (int j = 0; j < size - i - 1; j++)
{
if (array[j] > array[j + 1])
{ //when the current item is bigger than next
swapping(array[j],array[j + 1]);
swaps = 1; //set swap flag
}
}
if (!swaps)
break; // No swap in this pass,so array is sorted
}
}
int main()
{
int n;
cout << "Enter the number of elements: ";
cin >> n;
int arr[n]; //create an array with given number of elements
cout << "Enter elements:" << endl;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
cout << "Array before Sorting: ";
display(arr,n);
bubbleSort(arr,n);
cout << "Array after Sorting: ";
display(arr,n);
}
编辑 - 基本上代码在运行后退出而不接受任何输入。 现在我的 vsode 终端输出如下:-
C:\Projects>cd "c:\Projects\C++ - Projects\" && g++ bubblesort.cpp -o bubblesort && "c:\Projects\C++ - Projects\"bubblesort
Enter the number of elements: gggcd "c:\Projects\C++ - Projects\" && g++ bubblesort.cpp -o bubblesort && "c:\Projects\C++ - Projects\"bubblesort
Enter elements:
Array before Sorting:
Array after Sorting:
c:\Projects\C++ - Projects>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)