int main() { LL list; fstream fileobject("C:\\Users\\Jonathan\\output.txt"); // open a filestream string file; while (fileobject >> file) { //cout << file << endl; list.addLine(file); } fileobject.close(); for (short i = 0; i < 43; i++) { cout << list.getText() << endl; cout << endl; } system("Pause"); return 0; }
int main(){ LL<int> a; a.insert_at(0,12,a.get_head()); std::cout << "Current entries: "<< a.get_used()<<"\n"; std::cout << "Current capacity: "<< a.get_capacity()<<"\n"<<"\n"; a.insert_at(1,13,a.get_head()); std::cout << "Current entries: "<< a.get_used()<<"\n"; std::cout << "Current capacity: "<< a.get_capacity()<<"\n"<<"\n"; return 0; }
int main() { LL list; ifstream fileobject("C:\\Users\\Jonathan\\Documents\\states.txt"); // open a filestream (this path needs to be modified each time.. sorry) string file; while (getline(fileobject, file)) //loop through the text file and grab each line { list.addLine(file); //add the text to the node and then print using the .getText() function cout << list.getText() << endl << endl; } fileobject.close(); system("Pause"); return 0; }
std::string* Huffman::decompress(const std::vector<bool>* input) { encode = false; if(encoding == NULL || encoding->data == NULL || encoding->freqs == NULL) throw "no encoding set"; encoded = (void*)(new std::string()); LL* linkedlist = new LL(); unsigned int ll_size = 0; for(unsigned int i = 0; i < encoding->data->size(); i++) { linkedlist->insert(new Node(new char(encoding->data->at(i)), encoding->freqs->at(i))); ll_size++; } BinaryTree* bst = new BinaryTree(linkedlist, ll_size); Node* curr_node = bst->getFirst(); for(unsigned int i = 0; i < input->size() - overflow; i++) { if(!input->at(i)) { if(curr_node->left != NULL) curr_node = curr_node->left; }else if(input->at(i)) { if(curr_node->right != NULL) curr_node = curr_node->right; } if(curr_node->left == NULL && curr_node->right == NULL) { if(curr_node->character != NULL) { const char tmp[] = {*(curr_node->character), '\0'}; *((std::string*)encoded) += std::string(tmp); } curr_node = bst->getFirst(); } } delete linkedlist; delete bst; return (std::string*)encoded; }
/* Driver program to test above function */ int main() { LL start; /* The constructed linked list is: 1->2->3->4->5->6->7 */ start.push(7); start.push(6); start.push(5); start.push(4); start.push(3); start.push(2); start.push(1); cout << start.length() << endl; return 0; }
std::vector<bool>* Huffman::compress(const char* input, const size_t& size) { encode = true; LL* linkedlist = new LL(); unsigned int ll_size = 0; for(unsigned int i = 0; i < size; i++) { int* freq = linkedlist->getFreq(input[i]); if(freq == NULL) { linkedlist->insert(new Node(new char(input[i]))); ll_size++; }else{ (*freq)++; } } // sort linked list // I will use bubblesort, because we will have not so many Node* t0; for(int j = ll_size - 1; j > 0; j--) { for(int i = 0; i < j; i++) { LL* ll_f = linkedlist->get(i); LL* ll_s = linkedlist->get(i+1); if(ll_f->tree->freq > ll_s->tree->freq) { t0 = ll_f->tree; ll_f->tree = ll_s->tree; ll_s->tree = t0; } } } BinaryTree* bst = new BinaryTree(linkedlist, ll_size); std::unordered_map<char, std::vector<bool> >* map = new std::unordered_map<char, std::vector<bool> >(); bst->generateMapping(map); encoded = (void*)(new std::vector<bool>()); for(unsigned int i = 0; i < size; i++) { std::vector<bool>::iterator iter = map->at(input[i]).begin(); while(iter != map->at(input[i]).end()) { ((std::vector<bool>*)encoded)->push_back(*iter); iter++; } } delete map; this->encoding = new Huffman::Encoding(); this->encoding->data = new std::vector<char>(); this->encoding->freqs = new std::vector<int>(); for(int i = ll_size - 1; i >= 0 ; i--) { this->encoding->data->push_back(*(linkedlist->get(i)->tree->character)); this->encoding->freqs->push_back(linkedlist->get(i)->tree->freq); } delete linkedlist; delete bst; return (std::vector<bool>*)encoded; }