2013. 5. 21. 23:53

bubble sort / file open source code

#include "bubbleSort.h"

bubbleSort::bubbleSort(void)
{
}

bubbleSort::~bubbleSort(void)
{
}

int bubbleSort::startSort(int* arr_list, int size)
{
 int i, j, temp;
 for(i = 0 ; i < size ; i++){
  for(j = 0 ; j < size - 1 ; j++){
   if(arr_list[j] > arr_list[j+1])
   {
    temp = arr_list[j+1];
    arr_list[j+1] = arr_list[j];
    arr_list[j] = temp;
   }
  }
 }
 return 0;
}

int bubbleSort::fileopenTest()
{
 FILE* fileTest;
 FILE* fileOutput;
 int temp1, temp2, temp3;
 char c_temp1, c_temp2;

 fileTest = fopen("test1.txt", "rt");
 if(fileTest == NULL)
 {
  printf("file open error");
 }

 fileOutput = fopen("test2.txt", "wt");
 if(fileOutput == NULL)
 {
  printf("file open error2");
 }

 fscanf(fileTest, "%d\n", &temp1);
 printf("%d\n", temp1);

 for(int i = 0 ; i < 2 ; i++ )
 {
  fscanf(fileTest, "%c%c\n", &c_temp1, &c_temp2);
  fprintf(fileOutput, "(%c-%c)\n", c_temp1, c_temp2);
  fscanf(fileTest, "%d %d %d\n", &temp1, &temp2, &temp3);
  fprintf(fileOutput, "(%d)\n", temp1 + temp2 + temp3);
 }

 fclose(fileOutput);
 fclose(fileTest);

 return 0;
}

int main()
{
 int arr[10] = {123,456,2367,324,67,3213,545,12,4,997};
 bubbleSort sort;

 sort.startSort(arr, 10);

 for(int i = 0 ; i < 10 ; i++)
 {
  printf("%d ", arr[i] );
 }
 printf("\n");

 sort.fileopenTest();

 system("pause");
 return 0;
}