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 program that reads in a line consisting of a student’s name, Social Security number,...
Write a program that reads in a line consisting of a student’s name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element....
Write some C++ program segments that solves the indicated tasks (you do not have to write...
Write some C++ program segments that solves the indicated tasks (you do not have to write a complete program, nor be concerned about "good" output; a small code segment will be enough). a) A program that gets a double number from the user, decides whether that number is positive, negative, or zero and display its decision on the screen. a) A function isPositive that takes as input a double number and returns the integer 1 if the number is positive,...
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...
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...
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...
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...
Write a Java program that Reads baseball data in from a comma delimited file. Each line...
Write a Java program that Reads baseball data in from a comma delimited file. Each line of the file contains a name followed by a list of symbols indicating the result of each at bat: 1 for single, 2 for double, 3 for triple, 4 for home run, o for out, w for walk, s for sacrifice Statistics are computed and printed for each player. EXTRA CREDIT (+10 points); compute each player's slugging percentage https://www.wikihow.com/Calculate-Slugging-Percentage Be sure to avoid a...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
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...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world...
Write a 4-6 sentence summary explaining how you can use STL templates to create real world applications. In your summary, provide an example of a software project that you can create using STL templates and provide a brief explanation of the STL templates you will use to create this project. After that you will implement the software project you described . Your application must be a unique project and must incorporate the use of an STL container and/or iterator and...