File tree 1 file changed +84
-0
lines changed
1 file changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ using namespace std ;
3
+
4
+ struct node {
5
+ node *next[150 ] = {NULL };
6
+ int eow = 0 ;
7
+ string meaning = " kothariji" ;
8
+ }*head = NULL ,t1;
9
+
10
+ void insert (string s, string mean)
11
+ {
12
+ if (head == NULL )
13
+ head = new node;
14
+
15
+ node *temp = head;
16
+ int i = 0 ;
17
+ while (i< s.length () and temp -> next[s[i]-' a' ] != NULL )
18
+ {
19
+ temp = temp -> next[s[i]-' a' ];
20
+ i++;
21
+ }
22
+ while (i<s.length ())
23
+ {
24
+ node *t1 = new node;
25
+ temp -> next[s[i]-' a' ] = t1;
26
+ temp = t1;
27
+ i++;
28
+ }
29
+ temp -> meaning = mean;
30
+ }
31
+
32
+ void search (string s)
33
+ {
34
+ int i = 0 ,flag = 0 ;
35
+ node *temp = head;
36
+ while (i < s.length ())
37
+ {
38
+ if (temp -> next[s[i]-' a' ] == NULL )
39
+ {
40
+ flag =1 ;
41
+ break ;
42
+ }
43
+ temp = temp -> next[s[i]-' a' ];
44
+ i++;
45
+ }
46
+ if (flag == 0 and temp -> meaning != " kothariji" )
47
+ cout<<" Meaning: " <<" " <<temp -> meaning<<" \n\n " <<endl;
48
+ else
49
+ cout<<" No such word Found!" <<endl;
50
+ }
51
+
52
+ int main ()
53
+ {
54
+ string w, m;
55
+ while (1 )
56
+ {
57
+ int ch;
58
+ cout<<" Press 1 to insert a word and its meaning" <<endl;
59
+ cout<<" Press 2 to search meaning of a word" <<endl;
60
+ cout<<" Press 3 to exit" <<endl;
61
+ cin>>ch;
62
+ switch (ch)
63
+ {
64
+ case 1 : cout<<" Enter Word: " ;
65
+ cin>>w;
66
+ cout<<" Enter meaning: " ;
67
+ cin>>m;
68
+ insert (w,m);
69
+ cout<<" \n\n Word inserted successfully\n\n " <<endl;
70
+ break ;
71
+
72
+ case 2 : cout<<" Enter Word to search: " ;
73
+ cin>>w;
74
+ search (w);
75
+ break ;
76
+
77
+ case 3 : cout<<" Thanks for using our service!" <<endl;
78
+ return 0 ;
79
+
80
+ default : cout<<" Enter a valid input" <<endl;
81
+ break ;
82
+ }
83
+ }
84
+ }
You can’t perform that action at this time.
0 commit comments