Question: Hello, I created stacks in c coding language and added to these stacks the word that the user wants from the dictionary.txt file from
Hello, I created stacks in c coding language and added to these stacks the word that the user wants from the "dictionary.txt file from the dictionary and added it to the stacks. In this dictionary file, I found words with the same length as the word entered by the user but with a different single letter and added them to the word the user wanted. for each found word, I created separate stacks with the word you want from the user and enqueue them to the queue. Here, I tried to write a program in C programming language that takes a start word and a target word from the user, creates stacks until it reaches this target word, adds them to queues, dequeues the stacks from the queue whether the target word is reached or not, and if the word at the top of the stacks is equal to the target word, pops the words from the stacks and prints each word in the stack. But the program I wrote does not work. Since I am new in this business, I could not find where I am doing wrong. thank you. Here's the following my code:
#include
#include
#include
#define MAXWORDLENGTH
#define MAXDICTIONARYSIZE
Stack yaps
typedef struct
char wordsMAXDICTIONARYSIZEMAXWORDLENGTH;
int top;
Stack;
Queue yaps
typedef struct
Stack stacksMAXDICTIONARYSIZE;
int front, rear;
Queue;
Stack ilemleri
void initialStackStack stack
stacktop ;
int isStackEmptyStack stack
return stacktop ;
void pushStack stack char word
if stacktop MAXDICTIONARYSIZE
stacktop;
strcpystackwordsstacktop word;
else
printfStack overflow!
;
char popStack stack
if isStackEmptystack
return stackwordsstacktop;
else
return NULL;
Queue ilemleri
void initialQueueQueue queue
queuefront queuerear ;
int isQueueEmptyQueue queue
return queuefront ;
int isQueueFullQueue queue
return queuerear MAXDICTIONARYSIZE queuefront;
void enqueueQueue queue Stack stack
if isQueueFullqueue
if isQueueEmptyqueue
queuefront queuerear ;
else
queuerear queuerear MAXDICTIONARYSIZE;
queuestacksqueuerear stack;
else
printfQueue is full!
;
Stack dequeueQueue queue
Stack stack;
if isQueueEmptyqueue
stack queuestacksqueuefront;
if queuefront queuerear
queuefront queuerear ;
else
queuefront queuefront MAXDICTIONARYSIZE;
return stack;
else
printfQueue is empty!
;
initialStack&stack; Bo bir stack dndr
return stack;
Szlk dosyasndan kelime okuma ilemi
void readDictionaryStack stack char filename char userWord
FILE file fopenfilenamer;
if file NULL
printfDictionary file not found!
;
exit;
char wordMAXWORDLENGTH;
while fscanffiles word EOF
if strlenword strlenuserWord
int diff ;
int i;
for i ; i strlenword; i
if wordi userWordi
diff;
if diff
pushstack word;
fclosefile;
int main
char startWordMAXWORDLENGTH targetWordMAXWORDLENGTH;
printfEnter the start word: ;
scanfs startWord;
printfEnter the target word: ;
scanfs targetWord;
Queue queue;
initialQueue&queue;
Stack startStack;
initialStack&startStack;
push&startStack, startWord;
enqueue&queue, startStack;
while isQueueEmpty&queue
Stack currentStack dequeue&queue;
char currentWord poptStack;
if strcmpcurrentWord targetWord
printfPath found!
;
printfTransformation path: ;
while isStackEmptytStack
char word poptStack;
printfs word;
printfs
startWord;
break;
readDictionarytStack "dictionary.txt currentWord;
int i;
for i ; i currentStack.top; i
Stack newStack currentStack;
enqueue&queue, newStack;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
