I have a project on C Programming of a Thesaurus.
We are required to use any of the ADT's and I am having a hard time trying to figure out which adt to use.
Can anybody help?
Thanks.
I have a project on C Programming of a Thesaurus.
We are required to use any of the ADT's and I am having a hard time trying to figure out which adt to use.
Can anybody help?
Thanks.
care to explain what an ADT is, in this context?
What can this strange device be?
When I touch it, it gives forth a sound
It's got wires that vibrate and give music
What can this thing be that I found?
An Abstract Data Type.. Like Binary search tree ADT's, graph adt, tries, heap adt, etc..
I would use these ADT's in creating my database for my Thesaurus program.
But I'm not sure which adt to use.
I think a array of link lists might be a method of implementation.
But, it might or might not be a perfect fit for the problem domain.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
The question remains, though, how would you find the search word? Search every array of linked lists? Excuse the bizarre notation I'm about to use... I'm sure you'll understand it though.
[Mystery] --> Conundrum --> Puzzle --> Riddle --> Why
Say the search word was "Riddle", would you have an array entry for that as well, which might have different words in it's list (which is fine) as well as some repeated? Just trying to make sure I'm understanding you correctly.
[Riddle] --> Conundrum --> Puzzle --> Teaser
// Hodor
Definition -> 1st synonym -> 2nd synonym -> 3rd synonym
Depending on what needed might need another ADT pointing to the Definition.
To me, the solution needed depends on the real problem.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
O_oI think a array of link lists might be a method of implementation.
Thesaurus lives in memory: a "Trie" living over an ordered set of references to arrays containing ordered synonyms.
Thesaurus lives on a disc: a "B+Tree" living over arrays containing ordered synonyms of all words in the node.
Soma
[Edit]
[?]->[p]->[o]->[n]->[y](&Synonyms[Horse])
->[o]->[n]->[i]->[e]->[s](&Synonyms[Horse])
->[l]->[a]->[n](&Synonyms[Arrange], &Synonyms[Design])
Synonyms[Arrange] = (VERB)[Arrange, Draft]
Synonyms[Design] = (NOUN)[Procedure, Program]
Synonyms[Horse] = (NOUN)[Filly, Horse, Mare, Pony]
[/Edit]
Last edited by phantomotap; 03-17-2014 at 07:46 PM.
“Salem Was Wrong!” -- Pedant Necromancer
“Four isn't random!” -- Gibbering Mouther
Thank you for all your replies.
I have started creating a program and used Graph ADT as I understood it.
But I still have a problem in inserting. When I try to insert another set of words, the words that I have inserted before that seem to be gone from the list. I don't understand PLEASE HELP
Code:#include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> struct node { char word [20]; struct node *below, *synonym, *nxt; }; struct vertex { struct node *next; }; typedef struct vertex V; typedef struct node N; void display(N *node); int existingSyn(N *n, char s[20]); N *search(V *v, char w[20]); int checkNode(V *v, char w[20]); V *insert(V *v, char word [20], char syn [20]); N *create(char w [20]); N *create(char w [20]) { N *new; new = (N*)malloc(sizeof(N)); new -> below = NULL; new -> synonym = NULL; new -> nxt = NULL; strcpy(new->word, w); return (new); } void main() { int choice, flag; char word [20], syn [20], searchKey[20]; int logIn; V *v; N ........; v = NULL; ss = NULL; while(1) { clrscr(); printf("MENU\n1. Search\n2. Insert\n3. Exit \nCHOICE: "); scanf("%d", &choice); switch(choice) { case 1: printf("\nWORD: "); scanf("%s", searchKey); flag = checkNode(v, searchKey); if(flag == 0) { ss = search(v, searchKey); printf("%s has the following synonyms: ", searchKey); display(ss); getch(); } else if(flag !=0) { printf("\nWORD NOT FOUND!"); getch(); } break; case 2: printf("\nInput word: "); scanf("%s", word); getch(); printf("Synonym: "); scanf("%s", syn); getch(); v = insert(v, word, syn); getch(); break; case 3: exit(0); default: printf("\nINVALID INPUT. Press any key to try again..."); break; } } } V *insert(V *v, char word [20], char syn [20]) { int flag, existing; N *new, *newsyn, *temp; if (v==NULL) { new = create(word); newsyn = create(syn); v -> next = new; new -> synonym = newsyn; printf("\nINSERTED!\n"); } else { flag = checkNode(v, word); if (flag !=0) { temp = v -> next; while(temp!=NULL) { temp = temp -> below; } new = create(word); newsyn = create(syn); temp -> below = new; new -> synonym = newsyn; printf("\nINSERTED!\n"); } else if(flag == 0) { new = search(v,word); existing = existingSyn(new,syn); if(existing !=0) { temp = new -> synonym; while(temp->nxt!=NULL) { temp = temp -> nxt; } newsyn = create(syn); temp -> nxt = newsyn; printf("\nINSERTED!\n"); } else if(existing == 1) { printf("\nSynonym already exist in %s's records.", word); getch(); } } } return (v); } int checkNode(V *v, char w[20]) { int flag; N *temp; temp = v -> next; while(temp !=NULL) { /*if(temp->word == w) { printf("\nCHECKEDD!"); return (1); }**/ if(strcmp(temp -> word,w) == 0) { printf("\nCHECKED!\n"); return (0); } temp = temp -> below; } flag = strcmp(temp -> word,w); return (flag); } N *search(V *v, char w[20]) { N *temp; temp = v -> next; while(temp != NULL) { if(strcmp(temp->word,w)==0) { return (temp); } temp = temp -> below; } return (temp); } int existingSyn(N *n, char s[20]) { int flag; N *temp; temp = n -> synonym; while(temp != NULL) { /*if(temp->word==s) { return (1); }*/ if(strcmp(temp -> word,s)==0) { return (0); } temp = temp -> nxt; } flag = strcmp(temp -> word,s); return (flag); } void display(N *node) { N *temp; temp = node -> synonym; while(temp != NULL) { printf("\n%s", temp->word); temp = temp -> nxt; } } /* int Admin() { char user [20]; int pw; int flag = 0; clrscr(); printf("\n--ADMIN--\n"); printf("USERNAME: "); scanf("%s", user); printf("\nPASSWORD: "); scanf("%d", &pw); getch(); if(strcmp(user,"admin")==0 && pw == 123) { flag = 1; } else { printf("\nInvalid log -in!!"); } return (flag); }*/
I also have another question:
If you use file handling in C is it also possible to apply any of the ADT's?