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

DOC
Ds 2 cycle
PDF
#includeiostream struct node {    char value;    struct no.pdf
DOCX
Lab Week 2 Game Programming.docx
DOCX
EXP_2_stck implementation using linked list Code.docx
DOCX
Implement of c & its coding programming by sarmad baloch
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
PDF
solution in c++program Program to implement a queue using two .pdf
PDF
Double linked list header file below for FYI#include iostream.pdf
Ds 2 cycle
#includeiostream struct node {    char value;    struct no.pdf
Lab Week 2 Game Programming.docx
EXP_2_stck implementation using linked list Code.docx
Implement of c & its coding programming by sarmad baloch
#includeiostream #includecstdio #includecstdlib using na.pdf
solution in c++program Program to implement a queue using two .pdf
Double linked list header file below for FYI#include iostream.pdf

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

PPTX
The presention is about the queue data structure
PDF
Lab-2.4 101.pdf
PDF
137 Lab-2.2.pdf
DOCX
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
DOCX
Data structure lab on practical computer science.docx
DOCX
Data Structure lab on a practical in computer science
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PPTX
DSA(1).pptx
PPTX
Data Structures and Agorithm: DS 09 Queue.pptx
PDF
C++ Program to Implement Singly Linked List #includei.pdf
PPT
Link list part 2
PPTX
Linked list
PPTX
Queue oop
PDF
#include iostream #includestdlib.h using namespace std;str.pdf
PDF
double linked list header file code#include iostream#include.pdf
PDF
DSU C&C++ Practical File Diploma
PDF
DATA STRUCTURE USING C & C++
PPTX
Stack implementation using linked list ppt
DOCX
Solutionsfor co2 C Programs for data structures
DOCX
Binary Tree in C++ coding in the data structure
The presention is about the queue data structure
Lab-2.4 101.pdf
137 Lab-2.2.pdf
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
Data structure lab on practical computer science.docx
Data Structure lab on a practical in computer science
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DSA(1).pptx
Data Structures and Agorithm: DS 09 Queue.pptx
C++ Program to Implement Singly Linked List #includei.pdf
Link list part 2
Linked list
Queue oop
#include iostream #includestdlib.h using namespace std;str.pdf
double linked list header file code#include iostream#include.pdf
DSU C&C++ Practical File Diploma
DATA STRUCTURE USING C & C++
Stack implementation using linked list ppt
Solutionsfor co2 C Programs for data structures
Binary Tree in C++ coding in the data structure

More from arjuncp10 (20)

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

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
master seminar digital applications in india
PDF
RMMM.pdf make it easy to upload and study
PDF
01-Introduction-to-Information-Management.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
master seminar digital applications in india
RMMM.pdf make it easy to upload and study
01-Introduction-to-Information-Management.pdf
TR - Agricultural Crops Production NC III.pdf
Microbial disease of the cardiovascular and lymphatic systems
Renaissance Architecture: A Journey from Faith to Humanism
2.FourierTransform-ShortQuestionswithAnswers.pdf
Basic Mud Logging Guide for educational purpose
Supply Chain Operations Speaking Notes -ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O7-L3 Supply Chain Operations - ICLT Program
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf

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; }