faddu - #include <vector> #include...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #include <vector> #include <string> #include <stdlib.h> using namespace std; class Word{ private: string my_string ; int parse_array[26][50]; int freq[26]; int label[26]; void init_freq(){ for(int i=0 ; i<26;i++) freq[i] = 0; } void swap(int *a,int *b){ int temp; temp = *a; *a = *b; *b = temp; } public: Word(string inp_string){ this->my_string += inp_string; init_freq(); } void parse_string(){ int size = my_string.length(); char ch; for(int i =0 ; i < size;i++){ ch = my_string.at(i); parse_array[ch - 'a'][freq[ch - 'a']] = i; freq[ch - 'a']++; } } void qsort(int left,int right){ if( right <= left ){ return; } int left_start_point = left,right_start_point = right; int pivot = left++; int temp; while(1){ while(freq[left] >= freq[pivot] && left < right_start_point){ left++; } while(freq[right] < freq[pivot] && right > left_start_point){ right--; } if(right > left){ swap(&freq[left],&freq[right]); swap(&label[left],&label[right]); }else{ break; } } temp = right; if(freq[right] > freq[pivot]){ swap(&freq[right],&freq[pivot]); swap(&label[right],&label[pivot]);...
View Full Document

Page1 / 3

faddu - #include <vector> #include...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online