diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ab896f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +Makefile.win +justfct.cpp.dev diff --git a/justfct.cpp b/justfct.cpp new file mode 100644 index 0000000..ffa0cad --- /dev/null +++ b/justfct.cpp @@ -0,0 +1,249 @@ +#include "StdFunctions.h" + +#include "Functions.h" +#include "Stack.h" + +using namespace std; +Node* IncFrequency(Node* Head, char c) { + // This function searches for the character C in the simply linked list. + // If it was able to find a node containing this character, it increments it frequency by 1. + // If no such node exists, it creates a new node and append it to the beginning of the simply linked list, where : + // the 'txt' field is equal to the character + // the 'frequnecy' field is equal to 1 + // the 'parent', 'left' and 'right' fields are set to NULL +if(Head==NULL) +{ + cout<<"Head is null so creating LL from scratch..."<txt=c; + temp->next=NULL; + temp->left=NULL; + temp->right=NULL; + temp->parent=NULL; + temp->frequency=1; + + Head=temp; + + cout<next) +{ + + if(element->txt[0]==c) + { + element->frequency++; + cout<txt=c; + tmp->next=NULL; + tmp->left=NULL; + tmp->right=NULL; + tmp->parent=NULL; + tmp->frequency=1; + + + tmp->next=Head; + Head=tmp; + cout<next!=NULL;cur=cur->next) +{ + min=cur; + for(cur1=cur->next;cur1!=NULL;cur1=cur1->next) + { + if(compare(cur1,min)==-1) + { + min=cur1; + } + } + + if(compare(cur,min)==1) + { + int x=min->frequency; + min->frequency=cur->frequency; + cur->frequency=x; + + char s=min->txt[0]; + min->txt[0]=cur->txt[0]; + cur->txt=s; + } + +} + +DisplayList(Head); + +} + + + + +Node* InsertSorted(Node* Head, Node* elt) { + // This function inserts the node elt in the simply linked list while keeping the list + // sorted according to the frequencies of occurrence and the lexicographic order. + // For this purpose, you may use the already defined function : int compare(Node* First, Node* Second) + +Node *tmp=new Node; +tmp=elt; + +if(Head==NULL) +{ + cout<<"Head is null so creating a new LL with "<txt<<" as it's first node..."<next!=NULL;cur=cur->next) +{ + if(cur->txt==tmp->txt) + { + cout<<"Element found adding 1 to it's frequency..."<frequency++; + Sort(Head); + return Head; + } +} + +for(cur=Head;cur->next!=NULL&&compare(cur->next,tmp)==-1;cur=cur->next); + +cout<<"Adding "<txt<<" in the LL..."<next=cur->next; +cur->next=tmp; +Sort(Head); +return Head; + +} + + + +Node* SearchTree(Node* Tree, string C) { + // This function searchs the binary tree for the node containing the character C. + // It returns the a pointer to the node if such node exists + // or NULL if the character does not occur in the text + Node *temp=new Node; + temp=NULL; + if(Tree==NULL) + { + return NULL; + } + + if(Tree->txt==C) + { + return Tree; + } + + temp=SearchTree(Tree->right,C); + if(temp) + { + return temp; + } + + temp=SearchTree(Tree->left,C); + if(temp) + { + return temp; + } + + return NULL; + +} + +