Exemplo n.º 1
0
void printDictionary(treeNode* root)
{
	if(root != NULL)
	{
		root->DisplayWordMeaning();
		printDictionary(root->getLeft());
		printDictionary(root->getRight());
	}
	
}
Exemplo n.º 2
0
int main(int argc, char* argv[]){
   Dictionary A = newDictionary();
   printf("got jere");
   FILE* in = fopen("DictionaryClient2.c", "r");
   FILE* out = fopen("DictionaryClient2-out", "w");
   char* key;
   char* value;
   char* keyBuffer = NULL;
   char* valBuffer = NULL;
   int keyBufferOffset = 0, valBufferOffset = 0;
   int keyBufferLength = 0, valBufferLength = 0;
   char line[MAX_LEN+1];
   char label[MAX_LEN+1];
   int i, labelLength, lineLength, lineNumber = 0;
   
   // read input files
   while( fgets(line, MAX_LEN, in)!=NULL ){
      
      // put line in valBuffer
      lineNumber++;
      lineLength = strlen(line)-1;
      line[lineLength] = '\0';  // overwrite newline '\n' with null '\0'
      valBufferLength += (lineLength+1);
      valBuffer = realloc(valBuffer, valBufferLength*sizeof(char) );
      value = &valBuffer[valBufferOffset];
      strcpy(value, line);
      valBufferOffset = valBufferLength;
      
      // put label in keyBuffer
      sprintf(label, "line %d:\t", lineNumber);
      labelLength = strlen(label);
      keyBufferLength += (labelLength+1);
      keyBuffer = realloc(keyBuffer, keyBufferLength*sizeof(char) );
      key = &keyBuffer[keyBufferOffset];
      strcpy(key, label);
      keyBufferOffset = keyBufferLength;
   }

   // put keys and values in dictionary A
   keyBufferOffset = valBufferOffset = 0;
   for(i=0; i<lineNumber; i++){
      key = &keyBuffer[keyBufferOffset];
      value = &valBuffer[valBufferOffset];
      insert(A, key, value);
      keyBufferOffset += (strlen(key) + 1);
      valBufferOffset += (strlen(value) + 1);
   } 

   printDictionary(out, A);

   // free memory and close files
   freeDictionary(&A);
   free(keyBuffer);
   free(valBuffer);
   fclose(in);
   fclose(out);

   return(EXIT_SUCCESS);
}
int main(int argc, char* argv[]){
   Dictionary A = newDictionary();
   char* k;
   char* v;
   char* word1[] = {"one","two","three","four","five","six","seven"};
   char* word2[] = {"foo","bar","blah","galumph","happy","sad","blue"};
   int i;

   for(i=0; i<7; i++){
      insert(A, word1[i], word2[i]);
   }

   printDictionary(stdout, A);

   for(i=0; i<7; i++){
      k = word1[i];
      v = lookup(A, k);
      printf("key=\"%s\" %s\"%s\"\n", k, (v==NULL?"not found ":"value="), v);
   }

   // insert(A, "five", "glow"); // error: duplicate keys

   delete(A, "one");
   delete(A, "three");
   delete(A, "seven");

   printDictionary(stdout, A);

   for(i=0; i<7; i++){
      k = word1[i];
      v = lookup(A, k);
      printf("key=\"%s\" %s\"%s\"\n", k, (v==NULL?"not found ":"value="), v);
   }

   // delete(A, "one");  // error: key not found

   printf("%s\n", (isEmpty(A)?"true":"false"));
   printf("%d\n", size(A));
   makeEmpty(A);
   printf("%s\n", (isEmpty(A)?"true":"false"));

   freeDictionary(&A);

   return(EXIT_SUCCESS);
}
Exemplo n.º 4
0
void printDictionary(const TNODE * dictionary) {
    if (dictionary->translation)
        printf("\t%s\n", dictionary->translation);
    unsigned int i;
    for (i = 0; i < LETTERS; i++) {
        if (dictionary->child[i]) {
            printDictionary(dictionary->child[i]);
        }
    }
}
Exemplo n.º 5
0
int main(int argc, char* argv[]){
   int v;
   DictionaryRef A = newDictionary();

    insert(A, 1, 111);
    insert(A, 2, 222);
    insert(A, 3, 333);
    insert(A, 4, 444);
    insert(A, 5, 555);
    insert(A, 6, 666);
    insert(A, 7, 777);
    printDictionary(A, stdout);
    v = lookup(A, 1);
    printf("key=1 "); v==UNDEF?printf("not found\n"):printf("value=%d\n", v);
    v = lookup(A, 3);
    printf("key=3 "); v==UNDEF?printf("not found\n"):printf("value=%d\n", v);
    v = lookup(A, 7);
    printf("key=7 "); v==UNDEF?printf("not found\n"):printf("value=%d\n", v);
    v = lookup(A, 8);
    printf("key=8 "); v==UNDEF?printf("not found\n"):printf("value=%d\n", v);
    printf("\n"); 

    /* insert(A, 2, 666); */ /* causes insert() duplicate keys error */
    
    delete(A, 1);
    delete(A, 3);
    delete(A, 7);
    printDictionary(A, stdout);
    
    /* delete(A, 8); */ /* causes delete() non-existent key error */
    
    printf("%s\n", isEmpty(A)?"true":"false");
    printf("%d\n", size(A));
    makeEmpty(A);
    printf("%s\n", isEmpty(A)?"true":"false");
    printDictionary(A, stdout);
    
    freeDictionary(&A);
    return(EXIT_SUCCESS);
}
Exemplo n.º 6
0
void MyServer::startServer(){
    qDebug("Start server");

    if (isListening()){
        qDebug()<<"close server";
        close();
    }
    loadFile();
    printDictionary(dictionary);

    if (!listen(QHostAddress::Any, nPort)){
        qDebug()<<"Unable to start Server:"<<errorString();
        close();
        return;
    }
    connect(this, SIGNAL(newConnection()),this,SLOT(slotNewConnection()));
    qDebug() << isListening() << "TCPSocket listen on port" << nPort;
}
Exemplo n.º 7
0
int main(int argc, char* argv[]){
   Dictionary A = newDictionary();
   Dictionary B = newDictionary();
   Dictionary C = newDictionary();

   //insert() test-------------------------------------------------------
   insert(A,"1","Dan");
   insert(A,"2","brad");
   insert(A,"4","Richard");
   insert(A,"100","Matt");

   insert(B,"A","Tasha");
   insert(B,"G","Tammy");
      
   //to invoke exception
   //insert(D,"AS","rachel");
   //insert(B,"A","Tase");
   
   //size() test---------------------------------------------------------
   printf("%d\n",size(A));
   printf("%d\n",size(B));
   printf("%d\n",size(C));
   printf("\n");   
   //to invoke exception
   //printf("%d", size(D));

   //isEmpty() test------------------------------------------------------
   printf("%s\n", isEmpty(A)?"true":"false");
   printf("%s\n", isEmpty(C)?"true":"false");   
   printf("\n"); 
   //to invoke exception
   //printf("%s/n", isEmpty(D)?"true":"false");

   //lookup() test-------------------------------------------------------
   printf("%s\n",lookup(A,"1"));
   //printf("%s\n",lookup(A,"A"));
   printf("%s\n",lookup(A,"4"));
   printf("%s\n",lookup(A,"100"));
   printf("%s\n",lookup(B,"A"));
   //printf("%s\n",lookup(C,"2"));
   printf("\n");

   //makeEmpty() test----------------------------------------------------
   makeEmpty(B);
   //makeEmpty(D);
   
   //printDictionary() test----------------------------------------------
   printDictionary(stdout,A);
   printDictionary(stdout,B);
   
   //delete() test-------------------------------------------------------
   delete(A,"1");
   delete(A,"4");
   delete(A,"100");

   printDictionary(stdout,A);
   freeDictionary(&A);
   freeDictionary(&B);
   freeDictionary(&C); 
   return(EXIT_SUCCESS);
}