My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
A Real Dictionary using TRIES Data Structure
Posted Date:
Total Responses: 0
Posted By: Saurabh Member Level: Gold Points/Cash: 8
|
It uses a pointer 26^26 pointers to find the alphabet.I have attached the code for the project.It is a good project and this topic basically is new and no body knows about it. Cheers
#include #include #include #include #include #include
struct data { char word[20]; char meaning[50]; };
struct trie { struct trie *child[26]; struct data *ptr; };
struct trie *insert(struct trie* node, char *val, int len, int count) { if( node == NULL) { node = (struct trie*)malloc(sizeof(struct trie)); for(int i=0; i<26 ; i++) { node -> child[i] = NULL; } } if(count < len) { int temp = (int)(*(val+count))-65; node->child[temp] = insert(node->child[temp], val, len, (count+1) ); node->ptr = NULL; } else { node->ptr = (struct data*)malloc( sizeof(struct data) ); strcpy(node->ptr->word,val); printf(" Enter Meaning : " ); fflush(stdin); gets(node->ptr->meaning); } return node; }
struct trie *search(struct trie* node, char *val, int len, int count) { if( node == NULL) { printf("\n !!Word does not exist!!"); } else if(count < len) { int temp = (int)(*(val+count))-65; node->child[temp] = search( node->child[temp], val, len, (count+1) ); } else if(node->ptr == NULL) { printf("\n !!Word does not exist!!"); } else { printf("\n\n !!Word Exists!!"); printf("\n Word : %s", node->ptr->word ); printf("\n Meaning : %s\n", node->ptr->meaning ); } getch(); return node;
} struct trie *del(struct trie* node, char *val, int len, int count) { if( node == NULL) { printf("\n !!Word does not exist!!"); } else if(count < len) { int temp = (int)(*(val+count))-65; node->child[temp] = del( node->child[temp], val, len, (count+1) ); } else if(node->ptr == NULL) { printf("\n !!Word does not exist!!"); } else { free(node->ptr); node->ptr=NULL; printf("\n !!Word Deleted!! "); } getch(); return node; }
void display(struct trie* node) { if(node->ptr != NULL) { printf("\n Word : %s", node->ptr->word ); printf("\n Meaning : %s\n", node->ptr->meaning ); } else { clrscr(); gotoxy(30,12); printf("DICTIONARY EMPTY"); return; } for(int i=0; i<26; i++) { if(node->child[i] != NULL) display(node->child[i]);
else { clrscr(); gotoxy(30,12); printf("DICTIONARY EMPTY"); return; } } }
void prog() { char val[26],ch; int i; struct trie *root = NULL;
do { clrscr(); textmode(C80); gotoxy(30,5); textcolor(12); cprintf("THE COMPUTER DICTIONARY"); gotoxy(23,8); textcolor(15); cprintf("1. Insert an element"); gotoxy(23,10); cprintf("2. Search a Node"); gotoxy(23,12); cprintf("3. Delete a Node"); gotoxy(23,14); cprintf("4. Display a Node"); gotoxy(23,16); cprintf("5. Exit"); gotoxy(23,18); cprintf("Enter Your Choice");
ch=getche(); switch(ch) { case '1': clrscr(); printf("\n\n Enter Word : "); gets(val); i=strlen(val); root = insert(root, val, i-1, 0); break;
case '2': clrscr(); printf("\n\n Enter the Word to Search : "); gets(val); i=strlen(val); root = search(root, val, i-1, 0); break;
case '3': clrscr(); printf("\n\n Enter the Word to Delete : "); gets(val); i=strlen(val); root = del(root, val, i-1, 0); break;
case '4': clrscr(); printf("\t\t\t\tDisplay :\n"); display(root); getch(); break; case '5': clrscr(); textcolor(2); gotoxy(26,10); cprintf("QUITING THE DICTIONARY"); for(int i=0;i<=3;i++) { cprintf("."); delay(250); } return;
default: clrscr(); printf("\n\n !!WRONG CHOICE!!\n"); } }while(1); }
void intro() { textmode(C80); int i; clrscr(); for(i=0;i<=50;i++) { if((15+i)%2==0) { textcolor(4); gotoxy(30,5); cprintf("DICTIONARY LOADING"); } else { gotoxy(30,5); cout<<" "; } gotoxy(15+i,13); textcolor(5); cprintf("**>"); gotoxy(32,22); cout<<2*i<<"% completed"; delay(100); } delay(1000); clrscr(); gotoxy(26,10); cout<<"DICTIONARY LOADING COMPLETED"; delay(450); clrscr(); } void main() { clrscr(); intro(); prog(); }
|
Project Feedbacks
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|
|
|
| Post Feedback |
|
|
You must Sign In to post a feedback.
|
|
|
|
|
Advertise Here
|