0% found this document useful (0 votes)
2 views1 page

Queue Test

The document contains C++ code for implementing a queue using a linked list. It defines a structure for nodes and the queue, along with functions to initialize the queue, create nodes, check if the queue is empty, and push new nodes into the queue. The code includes basic error handling for memory allocation and manages the head and tail pointers of the queue.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Queue Test

The document contains C++ code for implementing a queue using a linked list. It defines a structure for nodes and the queue, along with functions to initialize the queue, create nodes, check if the queue is empty, and push new nodes into the queue. The code includes basic error handling for memory allocation and manages the head and tail pointers of the queue.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

...\source\repos\solution_finalDSA\finalDSA\finalDSA.

cpp 1
1 #include <iostream>
2 using namespace std;
3 struct node {
4 int info;
5 node* next;
6 };
7 struct queue {
8 node* head;
9 node* tail;
10 };
11 void khoitaoQueue(queue& q) {
12 [Link] = [Link] = NULL;
13 }
14 node* createnode(int x) {
15 node* p = new node;
16 if (p == NULL) exit(1);
17 p->info = x;
18 p->next = NULL;
19 return p;
20 }
21 bool isEmpty(queue q) {
22 return [Link] == NULL;
23 }
24 void push(queue& q, node* p) {
25 if ([Link] == NULL) [Link] = [Link] = p;
26 else {
27 [Link]->next = p;
28 [Link] = p;
29 }
30 }

You might also like