daily pastebin goal
55%
SHARE
TWEET

Untitled

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