daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. struct MinHeapNode {
  7.   char data;
  8.   unsigned freq;
  9.   MinHeapNode *left, *right;
  10.  
  11.   MinHeapNode(char data, unsigned freq)
  12.     {
  13.         left = right = NULL;
  14.         this->data = data;
  15.         this->freq = freq;
  16.     }
  17. };
  18.  
  19. void HuffmanCodes(char data[], int freq[], int size)
  20. {
  21.   for (int i=0; i<size; i++)
  22.   {
  23.     // add element
  24.   }
  25. }
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.   cout << "\n\n";
  30.  
  31. // variables
  32.   char letter;
  33.   char arr_c[10000] = {};
  34.   int arr_i[10000] = {};
  35.   int size = 0;
  36.  
  37. // error
  38.   if (argc != 2)
  39.   {
  40.     cout << "Error\n\n\n";
  41.     return 0;
  42.   }
  43.  
  44. // output files
  45.   ofstream preorder("preorder");
  46.   ofstream inorder("inorder");
  47.   ofstream code("code.txt");
  48.  
  49. // input file
  50.   ifstream file(argv[1]);
  51.  
  52. // file doesnt exist
  53.   if (!file)
  54.   {
  55.     cout << "Unable to open input file\n\n\n";
  56.     return 0;
  57.   }
  58.  
  59. // input
  60.   while (file >> letter)
  61.   {
  62.     cout << letter;
  63.  
  64.     for (int i=0; i<10000; i++)
  65.     {
  66.       if (arr_c[i] == letter)
  67.       {
  68.         arr_i[i]++;
  69.         break;
  70.       }
  71.       else if (arr_c[i] == 0)
  72.       {
  73.         arr_c[i] = letter;
  74.         arr_i[i] = 1;
  75.         size++;
  76.         break;
  77.       }
  78.     }
  79.   }
  80.  
  81. // sort
  82.   for (int i=0; i<size; i++)
  83.   {
  84.     int index = i;
  85.  
  86.     for (int j=i; j<size; j++)
  87.     {
  88.       if (arr_i[j] > arr_i[index])
  89.       {
  90.        index = j;
  91.       }
  92.     }
  93.     int temp1 = arr_c[i];
  94.     int temp2 = arr_i[i];
  95.  
  96.     arr_c[i] = arr_c[index];
  97.     arr_i[i] = arr_i[index];
  98.     arr_c[index] = temp1;
  99.     arr_i[index] = temp2;
  100.   }
  101.  
  102. // print
  103.   cout << endl << endl;
  104.   for (int i=0; i<size; i++)
  105.   {
  106.     cout << arr_c[i] << " " << arr_i[i] << endl;
  107.   }
  108.  
  109.   HuffmanCodes(arr_c, arr_i, size);
  110.  
  111.   cout << endl << "size : " << size << endl;
  112.  
  113.   file.close();
  114.  
  115.   cout << "\n\n\n";
  116.  
  117.   return 0;
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top