Question

You are working for one of the big airlines. Your manager asks you to create a...

You are working for one of the big airlines. Your manager asks you to create a sample program using queue data structure that explains how to board in the aircraft. Be sure to implement following things: Implement Queue data structure Enqueue Bonnai, Tim, Jerry and tom Display the front of the queue. It should be Bonnai Display the end of the queue. It should be Tom You need to perform following tasks to implement above example as queue data structure. Define the queue Add customernames one by one into the queue Print the front element Print the back element

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdlib.h>
#include <stdio.h>

// A linked list (LL) node to store a queue entry
struct QNode
{
   char *key;
   struct QNode *next;
};

// The queue, front stores the front node of LL and rear stores the
// last node of LL
struct Queue
{
   struct QNode *front, *rear;
};

// A utility function to create a new linked list node.
struct QNode* newNode(char k[])
{
   struct QNode *temp = (struct QNode*)malloc(sizeof(struct QNode));
   temp->key = k;
   temp->next = NULL;
   return temp;
}

// A utility function to create an empty queue
struct Queue *createQueue()
{
   struct Queue *q = (struct Queue*)malloc(sizeof(struct Queue));
   q->front = q->rear = NULL;
   return q;
}

// The function to add a key k to q
void enQueue(struct Queue *q, char k[])
{
   // Create a new LL node
   struct QNode *temp = newNode(k);

   // If queue is empty, then new node is front and rear both
   if (q->rear == NULL)
   {
   q->front = q->rear = temp;
   return;
   }

   // Add the new node at the end of queue and change rear
   q->rear->next = temp;
   q->rear = temp;
}
/*
// Function to remove a key from given queue q
struct QNode *deQueue(struct Queue *q)
{
   // If queue is empty, return NULL.
   if (q->front == NULL)
   return NULL;

   // Store previous front and move front one node ahead
   struct QNode *temp = q->front;
   q->front = q->front->next;

   // If front becomes NULL, then change rear also as NULL
   if (q->front == NULL)
   q->rear = NULL;
   return temp;
}*/

int main()
{
   struct Queue *q = createQueue();   //create queue data structure using createQueue() function
   enQueue(q,"Bonnai"); //enqueue Bonnai
   enQueue(q,"Tim");       //enqueue Tim
   enQueue(q,"Jerry");     //enqueue Jerry
   enQueue(q,"Tom");      //enqueue Tom
   printf("Queue front : ");
   printf("%s\n",q->front->key); //q->front points to the front node and key points to the data element of front node
   printf("Queue rear : ");
   printf("%s\n",q->rear->key);    //q->rear points to the rear node and key points to the data element of rear node
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
You are working for one of the big airlines. Your manager asks you to create a...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to implement a queue using linked lists. You can use the queue...

    Write a C++ program to implement a queue using linked lists. You can use the queue data structure from the Standard Template Library (STL). The program should provide the following functionality: Enqueue data into queue Dequeue data from queue Print data at the front Print data at the back Print the entire queue Check if the queue is empty Print the number of elements in the queue Test your program using at least the following test cases (considering the queue...

  • (java) Please implement your own Dequeue class which has following methods •boolean add(E e)= void addLast(E...

    (java) Please implement your own Dequeue class which has following methods •boolean add(E e)= void addLast(E e)  // two methods are the same. You could implement either one • •void addFirst(E e) • •E getFirst( ) = E peek( ) // two methods are the same. You could implement either one •E getLast( ) •E removeFirst() •E removeLast() Case 1 : Queue •Create a queue which is an instance of Dequeue. The queue should perform with given following input and print...

  • HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE...

    HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD COMMENTS: stackARRAY: #include<iostream> #define SIZE 100 #define NO_ELEMENT -999999 using namespace std; class Stack { int arr[SIZE]; // array to store Stack elements int top; public: Stack() { top = -1; } void push(int); // push an element into Stack int pop(); // pop the top element from Stack int topElement(); // get the top element void display(); // display Stack elements from top to bottom }; void Stack...

  • You are working as a software developer for a large insurance company. Your company is planning...

    You are working as a software developer for a large insurance company. Your company is planning to migrate the existing systems from Visual Basic to Java and this will require new calculations. You will be creating a program that calculates the insurance payment category based on the BMI score. Your Java program should perform the following things: Take the input from the user about the patient name, weight, birthdate, and height. Calculate Body Mass Index. Display person name and BMI...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • Your assignment is to create and test a class for a queue of objects. You may...

    Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue.   The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...

  • CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....

    CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...

  • In this lab, using C++, you will create an abstract data type, using a doubly-linked circular...

    In this lab, using C++, you will create an abstract data type, using a doubly-linked circular structure to store the values and links. You must create it by your own and not use any existing containers. You will need a QueueNode. You can use a struct for this, as each node will not have any associated functions. It will have members for data, and the next and previous pointers. Data will be positive integers. There will be no NULL pointers....

  • Goals This assignment is an individual assignment and you will work on it on your own....

    Goals This assignment is an individual assignment and you will work on it on your own. The goal of this assignment is to be able to use stacks and queues, and to master and have an in-depth understanding of such primitive ADTs. In this assignment you will build a more complex ADT using the primitive stack and queue ADTs. Moreover, an important goal of this assignment is to be able to analyze an ADT that you will build yourself using...

  • In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is...

    In this assignment, you are given several classes in the cpp file “DList.cpp”. Your task is to complete the implementation of the classes specified as below. Y 1 Your Task You are given a class “Item” that contains one integer value, and two pointers. You are going to build a doubly linked list class DLinkedList. I describe the tasks below. Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure that the copy constructor makes...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT