배열을 이용한 간단한 선형 Queue

#define MAX_QUEUE_SIZE 6
static char queue[MAX_QUEUE_SIZE];

int main(void)
{
 int front, rear;
        front = rear = -1;
        int ret;
   
        addQeueu(&rear, 'A');
        addQeueu(&rear, 'B');
        addQeueu(&rear, 'C');
        ret = delQueue(&front, rear);

        system("pause");
        return 0;
}

void addQeueu(int last, int data)
{
 if(*last == MAX_QUEUE_SIZE - 1) {
  queue_full();   // 구현은 생략
                return;
 }
 queue[++*last] = data;
}

void delQueue(int first, int last)
{
 if(*first == last) {
   return queue_empty();  // 구현은 생략
        }
        return queue[++*first];
}


    

 

2013. 6. 23. 16:05

작명학 관련 정보

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;
}