SlideShare a Scribd company logo
C++
Write a function void headEnqueue(Queue *q, int key) which enqueues the key such that, at
function exit, it is positioned at the head of the queue rather than the tail; and the order and
integrity of the queue is otherwise maintained.
Solution
struct node
{
int data;
node* next;
};
class Queue //linked_list class
{
private:
node* front;
node* rear;
public:
Queue();
void insert(int);
headEnqueue(Queue *q, int key);
};
Queue::Queue()
{
front = rear = NULL;
}
void Queue::insert(int val)
{
node* temp = new node;
temp->data = val;
temp->next = NULL;
if (front == NULL)
front= rear = temp;
else {
node* temp1 = front;
while (temp1->next)
temp1 = temp1->next;
temp1->next = temp;
}
}
void Queue::headEnqueue(Queue *q, int key)
{
node* temp = new node;
temp->data = key;
temp->next=q->front;
q->front=temp;
}

More Related Content

Similar to C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf (20)

PPTX
Queue oop
Gouda Mando
 
PDF
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
rozakashif85
 
PDF
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
DOCX
Create a Queue class that implements a queue abstraction. A queue is.docx
rajahchelsey
 
PPTX
Implementation of queue using singly and doubly linked list.
central university of bihar
 
PPTX
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
PDF
Consider an extension of the queue abstract data type, called a .pdf
arorasales234
 
PPTX
Queues_0748555555555555555555555526.pptx
nailapp2023
 
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 7.pdf
Chethan Raddi
 
PPT
computer notes - Data Structures - 9
ecomputernotes
 
PPTX
Basic Queue Operation in DataStructure.pptx
LakshmiSamivel
 
PDF
Queue
pooja kumari
 
PDF
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
sktambifortune
 
PPTX
Chapter 4 data structure and algorithm - Stacks and Queues
afendimohammed288
 
PDF
double Skiplist code below#include iostream#include vector.pdf
txkev
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
PDF
chapter10-queue-161018120329.pdf
ssuserff72e4
 
PPTX
Stack implementation using linked list ppt
JayasankarShyam
 
PDF
Linked List Implementation of Queue in C
Kasun Ranga Wijeweera
 
Queue oop
Gouda Mando
 
Data StructuresPLEASE USING THIS C++ PROGRAM BELOW, I NEED HEL.pdf
rozakashif85
 
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
Create a Queue class that implements a queue abstraction. A queue is.docx
rajahchelsey
 
Implementation of queue using singly and doubly linked list.
central university of bihar
 
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
Consider an extension of the queue abstract data type, called a .pdf
arorasales234
 
Queues_0748555555555555555555555526.pptx
nailapp2023
 
Data Structures and Algorithms-DSA_Linkedlist_class 7.pdf
Chethan Raddi
 
computer notes - Data Structures - 9
ecomputernotes
 
Basic Queue Operation in DataStructure.pptx
LakshmiSamivel
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
sktambifortune
 
Chapter 4 data structure and algorithm - Stacks and Queues
afendimohammed288
 
double Skiplist code below#include iostream#include vector.pdf
txkev
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
chapter10-queue-161018120329.pdf
ssuserff72e4
 
Stack implementation using linked list ppt
JayasankarShyam
 
Linked List Implementation of Queue in C
Kasun Ranga Wijeweera
 

More from arjuncp10 (20)

PDF
I l Show that if X has the discrete topology, then its only conn.pdf
arjuncp10
 
PDF
In 2006 the CEO of Bear Sterns, James Caynes, received a compensatio.pdf
arjuncp10
 
PDF
How would a CFE devise a plan to prevent subsequent employee fraud.pdf
arjuncp10
 
PDF
Hilary rode her horse for 8 miles until it was hurt.Then she walked .pdf
arjuncp10
 
PDF
fully comments for my program, thank you will thumb up#include io.pdf
arjuncp10
 
PDF
Find the admittance Yab in the circuit seen in the figure. Take that.pdf
arjuncp10
 
PDF
Diversity Paper Each student will complete a diversity research assig.pdf
arjuncp10
 
PDF
Detailed solutions please 1. Let R and S be commutative rings and le.pdf
arjuncp10
 
PDF
Describe the mechanisms of asexual reproduction inProkaryotesPr.pdf
arjuncp10
 
PDF
Define intermediate phenotype and then imagine some intermediate phe.pdf
arjuncp10
 
PDF
Consider a population of lizards living on the coast of Africa. A sto.pdf
arjuncp10
 
PDF
Can “discovery science” (for example, the discovery of a new species.pdf
arjuncp10
 
PDF
All of the following are features or functions of nanobodies except _.pdf
arjuncp10
 
PDF
A girl running at a constant speed of 1.4ms in a straight line thro.pdf
arjuncp10
 
PDF
You have a rural dial-up customer who complains that a large number .pdf
arjuncp10
 
PDF
You are given a mixed culture containing a anaerobic thermophile, ae.pdf
arjuncp10
 
PDF
Woyld removing phenylethyl alcohol from PEA alter the mediumsS.pdf
arjuncp10
 
PDF
Which abstraction uses slates, state transitions, inputs and outputs .pdf
arjuncp10
 
PDF
What is the target cell for the hormone AngiotensionogenSolut.pdf
arjuncp10
 
PDF
What is a possible evolutionary advantage of having intronsexons in.pdf
arjuncp10
 
I l Show that if X has the discrete topology, then its only conn.pdf
arjuncp10
 
In 2006 the CEO of Bear Sterns, James Caynes, received a compensatio.pdf
arjuncp10
 
How would a CFE devise a plan to prevent subsequent employee fraud.pdf
arjuncp10
 
Hilary rode her horse for 8 miles until it was hurt.Then she walked .pdf
arjuncp10
 
fully comments for my program, thank you will thumb up#include io.pdf
arjuncp10
 
Find the admittance Yab in the circuit seen in the figure. Take that.pdf
arjuncp10
 
Diversity Paper Each student will complete a diversity research assig.pdf
arjuncp10
 
Detailed solutions please 1. Let R and S be commutative rings and le.pdf
arjuncp10
 
Describe the mechanisms of asexual reproduction inProkaryotesPr.pdf
arjuncp10
 
Define intermediate phenotype and then imagine some intermediate phe.pdf
arjuncp10
 
Consider a population of lizards living on the coast of Africa. A sto.pdf
arjuncp10
 
Can “discovery science” (for example, the discovery of a new species.pdf
arjuncp10
 
All of the following are features or functions of nanobodies except _.pdf
arjuncp10
 
A girl running at a constant speed of 1.4ms in a straight line thro.pdf
arjuncp10
 
You have a rural dial-up customer who complains that a large number .pdf
arjuncp10
 
You are given a mixed culture containing a anaerobic thermophile, ae.pdf
arjuncp10
 
Woyld removing phenylethyl alcohol from PEA alter the mediumsS.pdf
arjuncp10
 
Which abstraction uses slates, state transitions, inputs and outputs .pdf
arjuncp10
 
What is the target cell for the hormone AngiotensionogenSolut.pdf
arjuncp10
 
What is a possible evolutionary advantage of having intronsexons in.pdf
arjuncp10
 

Recently uploaded (20)

PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPSX
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
PPTX
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PDF
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
PPTX
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Health Planning in india - Unit 03 - CHN 2 - GNM 3RD YEAR.ppsx
Priyanshu Anand
 
How to Configure Lost Reasons in Odoo 18 CRM
Celine George
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
digestive system for Pharm d I year HAP
rekhapositivity
 
Federal dollars withheld by district, charter, grant recipient
Mebane Rash
 
How to Configure Storno Accounting in Odoo 18 Accounting
Celine George
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPT on the Development of Education in the Victorian England
Beena E S
 

C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf

  • 1. C++ Write a function void headEnqueue(Queue *q, int key) which enqueues the key such that, at function exit, it is positioned at the head of the queue rather than the tail; and the order and integrity of the queue is otherwise maintained. Solution struct node { int data; node* next; }; class Queue //linked_list class { private: node* front; node* rear; public: Queue(); void insert(int); headEnqueue(Queue *q, int key); }; Queue::Queue() { front = rear = NULL; } void Queue::insert(int val) { node* temp = new node; temp->data = val; temp->next = NULL; if (front == NULL) front= rear = temp;
  • 2. else { node* temp1 = front; while (temp1->next) temp1 = temp1->next; temp1->next = temp; } } void Queue::headEnqueue(Queue *q, int key) { node* temp = new node; temp->data = key; temp->next=q->front; q->front=temp; }