현재이 프로그램은 텍스트 파일의 이름을 입력하면 작동합니다.이 버블 정렬 조정 방법
방금 텍스트 파일을 열어 방망이를 수행하고 (현재 상태에서 수행) 버블 정렬을 수행하는 것으로 알려주려고합니다. 텍스트 파일
예 :
-14, -5, 7, 1, 7, 71, -3, 59 거품 짧은] -14, -5, -3, 1, 7, 7, 59, 71
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <vector>
using namespace std;
void bubbsort(int arr[]);
int main()
{
string file;
const int a = 100, b = 10, c = 10;
int count = 0, count1 = 0, d = 0, swap = 0;
int clam[a] = { 0 }, ray[b][c] = { 0 };
cout << "Type name of the file: " << endl;
cin >> file;
ifstream data;
data.open(file);
vector<int> array;
int number;
while (data >> number);
{
array.push_back(number);
count++;
d = count;
clam[count];
}
data.close();
data.open(file);
while (data.good())
{
int i;
for (i = 0; i<d; i++)
{
data >> clam[i];
cout << clam[i] << " ";
count1++;
}
}
cout << endl << "There are " << d << " integers within " << ' " ' << file << '"' << " file!" << endl;
data.close();
for (int k = 0; k <= count - 1; k++)
{
for (int l = k + 1; l <= count - 1; l++)
{
int temp = 0;
if (clam[k]>clam[l]){
temp = clam[k];
clam[k] = clam[l];
clam[l] = temp;
swap++;
}
}
}
cout << endl << "Sorting this " << swap << " # of swaps" << endl;
data.close();
cout << endl;
for (int y = 0; y<count; y++)
{
for (int z = 0; z <= 9; z++)
{
if (y != count)
{
cout << right << setw(4) << clam[y];
y++;
}
else
{
cout << endl;
system("pause");
return 0;
}
}
y = y - 1;
cout << endl;
}
system("pause");
return 0;
}
infile 함수의 이름을 바꾸는 것이 트릭을 수행하지 않은 것으로 보입니다.이 방법을 조정하는 방법은 잘 모르겠습니다.
여러 텍스트 파일 (다른 파일 이름)을 사용 하시겠습니까? "박쥐 오른쪽으로 열어 라"는 지시는 그렇지 않다는 뜻인가? – HvS
이 주변에는 방법이 많지 않습니다. 파일 이름이 고정되면 하드 코드하십시오. 어떤 단계에서 파일 이름을 입력하지 않아도되는 또 다른 옵션은 응용 프로그램 경로에서 특정 확장명을 가진 하나 이상의 파일을 읽도록 응용 프로그램을 수정하는 것입니다 (일부 제약이 필요합니다). – HvS