Question

Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has...

Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has the following methods: clear – clears the queue; is_empty – returns 1 if the queue is empty, otherwise 0; is_full – returns 1 if the queue is full, otherwise 0; add – adds a new string at the end of the queue; remove – removes the string from the front of the queue. Use ADT queue to solve the following problems: • Write an interactive program that adds and removes elements from the queue. • Use ADT queue to find the way out from a maze. The maze is an 8 x 8, 2 D array of characters, ‘*’ indicating a wall. The program reads the starting point from which the way out is found. This kind of search is called breadth-first-search.

Input File:

********
* * *** 
**  *  *
** *** *
*   * **
*   *  *
*** * **
*** ****

Homework Answers

Answer #1

   #include<stdio.h>

   #include<stdlib.h>

   #define MAXIMUM 100

   #define intial 1

   #define waitng 2

   #define visiited 3

   int n;

   int adj[MAXIMUM][MAXIMUM];

   int state[MAXIMUM];

   void create_Graph();

   void breadth_First_Search_Traversal();

   void breadth_First_Search(int v);

   int que[MAXIMUM], frnt = -1,rearr = -1;

   void insert-Queue(int vertex);

   int delete_Queue();

   int is_Empty_Queue();

   int main()

   {

   create_Graph();

   breadth_First_Search_Traversal();

   return 0;

   }

   void breadth_First_Search_Traversal()

   {

   int h;

   for(h=0; h<n; h++)

   state[h] = intial;

   printf("Enter Start Vertex for breadth_First_Search: \n");

   scanf("%d", &h);

   breadth_First_Search(h);

   }

   void breadth_First_Search(int h)

   {

   int i;

   insert-Queue(h);

   state[h] = waitng;

   while(!is_Empty_Queue())

   {

   h= delete_Queue( );

   printf("%d ",h);

   state[h] = visiited;

   for(i=0; i<n; i++)

   {

   if(adj[h][i] == 1 && state[i] == intial)

   {

   insert-Queue(i);

   state[i] = waitng;

   }

   }

   }

   printf("\n");

   }

   void insert-Queue(int vertex)

   {

   if(rearr == MAXIMUM-1)

   printf("Queue Overflow\n");

   else

   {

   if(frnt == -1)

   frnt = 0;

   rearr = rearr+1;

   que[rearr] = vertex ;

   }

   }

   int is_Empty_Queue()

   {

   if(frnt == -1 || frnt > rearr)

   return 1;

   else

   return 0;

   }

   int delete_Queue()

   {

   int deleteitem;

   if(frnt == -1 || frnt > rearr)

   {

   printf("Queue Underflow\n");

   exit(1);

   }

   deleteitem = que[frnt];

   frnt = frnt+1;

   return deleteitem;

   }

   void create_Graph()

   {

   int cnt,max_Edge,orgn,destn;

   printf("Enter number of vertices : ");

   scanf("%d",&n);

   max_Edge = n*(n-1);

   for(cnt=1; cnt<=max_Edge; cnt++)

   {

   printf("Enter edge %d( -1 -1 to quit ) : ",cnt);

   scanf("%d %d",&orgn,&destn);

   if((orgn == -1) && (destn == -1))

   break;

   if(orgn>=n || destn>=n || orgn<0 || destn<0)

   {

   printf("Invalid edge!\n");

   cnt--;

   }

   else

   {

   adj[orgn][destn] = 1;

   }

   }

   }

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
Note: Do not use classes or any variables of type string to complete this assignment Write...
Note: Do not use classes or any variables of type string to complete this assignment Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
Write a program of wordSearch puzzle that use the following text file as an input. The...
Write a program of wordSearch puzzle that use the following text file as an input. The output should be like this: PIXEL found (left) at (0,9). ( Use JAVA Array ) .Please do not use arrylist and the likes! Hints • The puzzle can be represented as a right-sized two-dimensional array of characters (char). • A String can be converted into a right-sized array of characters via the String method toCharArray. . A word can occur in any of 8...
**please write code with function definition taking in input and use given variable names** for e.g....
**please write code with function definition taking in input and use given variable names** for e.g. List matchNames(List inputNames, List secRecords) Java or Python Please Note:    * The function is expected to return a STRING_ARRAY.      * The function accepts following parameters:      *  1. STRING_ARRAY inputNames      *  2. STRING_ARRAY secRecords      */ Problem Statement Introduction Imagine you are helping the Security Exchange Commission (SEC) respond to anonymous tips. One of the biggest problems the team faces is handling the transcription of the companies reported...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT