Question

In: Computer Science

Give the algorithms in pseudo code of the enqueue and dequeue procedures. Constraint: the structure implementing...

Give the algorithms in pseudo code of the enqueue and dequeue procedures.
Constraint: the structure implementing the queue must only be pointed to by a single field (example: head, tail or number of elements, etc.)

Solutions

Expert Solution

Queue:

A queue is a linear data structure in which addition is done at the one end and deletion is one at another end.

Insertion can be performed at the rear end.

Deletion can be performed at the front end.

Pseudocode:

The informal language to develop an algorithm used by the programmer is known as pseudocode. This describes the text-based step by step solution to the given problem that is intended for human reading.

The pseudo code of the enqueue is given below:

Step 1: Start

Step 2: Declare variable x

Step 3: Input variable x

Step 4: struct node *ptr = head

Step 5: struct node *link = (struct node*) malloc(sizeof(struct node))

Step 6: link->data = data

Step 7: link->next = NULL;

Step 8: while ptr != NULL

Step 8.1: ptr = ptr->next

Step 9: ptr->next = link

Step 10: Stop

The pseudo code of the dequeue is given below:

Step 1: Start

Step 2: struct node *ptr = head

Step 3:  if ptr == NULL

Step 3.1: return

Step 4: struct node* temp = head

Step 5: head = temp->next

Step 6: free(temp)

Step 7: Stop  


Related Solutions

Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java...
Develop an algorithm for INSERTION SORT. Give the pseudo-code version. Convert your pseudo-code into a Java program.
I need this in PSEUDO CODE: This looks long, but only because I have to give...
I need this in PSEUDO CODE: This looks long, but only because I have to give you my answer to the first part. First part of the questions (already answered) GDOT has contacted you to help write code to control the cross walk signals in Georgia. You must create a Crosswalk Signal class with three hidden attributes (Walk, Hurry and Wait), two constructors (a default that sets all lights to on and an overloaded that sets Hurry to on for...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code...
Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code formatting and documentation. A student has established the following monthly budget: Budget Categories       Budgeted amount ----------------------------------------------------- Housing                  $ 580.00 Utilities                   $ 150.00 Household Expenses    $ 65.00 Transportation           $ 50.00 Food                      $ 250.00 Medical                  $ 30.00 Insurance                $ 100.00 Entertainment           $ 150.00 Clothing                  $ 75.00 Miscellaneous           $ 50.00 ---------------------------------------------------- Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define two MonthlyBudget structure variables...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT