C++ Queue LinkedList

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ Queue LinkedList, Refer to the codes I've made as a guide and add functions where it can add/insert/remove function to get the output of the program, refer to the image as an example of input & output. Put a comment or explain how the program works/flow.

***Queue Linked List Implementation***
What do you want to do?
Enter letter of choice: c
Queue:
NULL
a. Inqueue item into the Queue
b. Dequeue item out of the Queue
c. Display Queue
Run program again? Press y if yes: y
What do you want to do?
Enter letter of choice: b
You can't dequeue from an empty Queue
Run program again? Press y if yes: y
What do you want to do?
Queue:
0
a. Inqueue item into the Queue
b. Dequeue item out of the Queue
c. Display Queue
Enter letter of choice: a
Enter the item to the queue: 0
Queue:
0 1
a. Inqueue item into the Queue
b. Dequeue item out of the Queue
c. Display Queue
Enqueue more item? Press if yes: y
Enter item to the queue: Y
Enqueue more item? Press
Enter item to the queue:
Queue:
012
Enqueue more item? Press
Enter item to the queue: ž
Queue:
0 1 2 3
Enqueue more item? Press y if yes: n
Ending Enqueue function...
if yes: y
Run program again? Press y if yes: y
What do you want to do?
Enter letter of choice: c
Queue:
0 1 2 3
if yes: y
Queue:
1 2 3
Run program again? Press y if yes: y
What do
want to do?
Dequeue more items? Press y if yes: y
How many items to be dequeued off the Queue? 2
Queue:
3
a. Inqueue item into the Queue
b. Dequeue item out of the Queue
c. Display Queue
Dequeue more items? Press y if yes: y
How many items to be dequeued off the Queue? 2
You can't dequeue from an empty Queue
a. Inqueue item into the Queue
b. Dequeue item out of the Queue
c. Display Queue
Enter letter of choice: b
How many items to be dequeued off the Queue? 1
Transcribed Image Text:***Queue Linked List Implementation*** What do you want to do? Enter letter of choice: c Queue: NULL a. Inqueue item into the Queue b. Dequeue item out of the Queue c. Display Queue Run program again? Press y if yes: y What do you want to do? Enter letter of choice: b You can't dequeue from an empty Queue Run program again? Press y if yes: y What do you want to do? Queue: 0 a. Inqueue item into the Queue b. Dequeue item out of the Queue c. Display Queue Enter letter of choice: a Enter the item to the queue: 0 Queue: 0 1 a. Inqueue item into the Queue b. Dequeue item out of the Queue c. Display Queue Enqueue more item? Press if yes: y Enter item to the queue: Y Enqueue more item? Press Enter item to the queue: Queue: 012 Enqueue more item? Press Enter item to the queue: ž Queue: 0 1 2 3 Enqueue more item? Press y if yes: n Ending Enqueue function... if yes: y Run program again? Press y if yes: y What do you want to do? Enter letter of choice: c Queue: 0 1 2 3 if yes: y Queue: 1 2 3 Run program again? Press y if yes: y What do want to do? Dequeue more items? Press y if yes: y How many items to be dequeued off the Queue? 2 Queue: 3 a. Inqueue item into the Queue b. Dequeue item out of the Queue c. Display Queue Dequeue more items? Press y if yes: y How many items to be dequeued off the Queue? 2 You can't dequeue from an empty Queue a. Inqueue item into the Queue b. Dequeue item out of the Queue c. Display Queue Enter letter of choice: b How many items to be dequeued off the Queue? 1
1 #include <iostream>
2
using namespace std;
3
4 class Node
58{
6
7
8
15
16
17
18
19 };
20
9
10
};
11 class Linked List public Node
12 {
13
public:
14
21
22
23
HH H
24
25
26
27
28
29
30
31
32
33
34
35
{
}
Node::Node()
//ctor
{
public:
}
LinkedList::LinkedList()
{
Node();
int value;
Node" next;
}
void LinkedList::printLinked List (Node* n)
47
48
LinkedList();
49
void printLinked List (Node* n);
50
void insertAtTheFront (Node** head, int newValue); 51
void insertAtThe End (Node** head, int newValue);
void insertAfter (Node* previous, int newValue);
52
53
54
55
56
57
58
59
//ctor
{
while(n!=NULL)
}
36
37
38
39
40
41
42
43
44
45
46
cout << n->value << endl;
n=n->next;
60
61
62
63
64
65
66
67
68
69
70
71
void LinkedList::insertAtTheFront (Node** head, int newValue)
{
Node newNode = new Node();
newNode->value=newValue;
newNode->next="head;
*head=newNode;
}
void LinkedList::insertAt The End (Node** head, int newValue)
{
Node* newNode= new Node();
newNode->value = newValue;
newNode->next = NULL;
if (*head = NULL)
{
*head=newNode;
}
Node" last=*head;
while(last->next!=NULL)
last-last->next;
{
}
return;
last->next=newNode;
}
void LinkedList::insertAfter (Node* previous, int newValue)
{
if(previous ==NULL)
{
cout << "Previous node cannot be NULL.";
return;
}
Node* newNode = new Node();
newNode->value=newValue;
newNode->next-previous->next;
previous->next=newNode;
73 int main()
74 {
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
}
Node head = new Node();
Node* second = new Node();
Node* third new Node();
head->value=1;
head->next=second;
second->value=2;
second->next=third;
third->value=4;
third->next=NULL;
LinkedList 11;
11.insertAtTheFront (&head, -1);
11.insertAtThe End (&head, 5);
11.insertAfter (head, 0);
11.insertAfter (second, 3);
11.printLinkedList (head);
return 0;
Transcribed Image Text:1 #include <iostream> 2 using namespace std; 3 4 class Node 58{ 6 7 8 15 16 17 18 19 }; 20 9 10 }; 11 class Linked List public Node 12 { 13 public: 14 21 22 23 HH H 24 25 26 27 28 29 30 31 32 33 34 35 { } Node::Node() //ctor { public: } LinkedList::LinkedList() { Node(); int value; Node" next; } void LinkedList::printLinked List (Node* n) 47 48 LinkedList(); 49 void printLinked List (Node* n); 50 void insertAtTheFront (Node** head, int newValue); 51 void insertAtThe End (Node** head, int newValue); void insertAfter (Node* previous, int newValue); 52 53 54 55 56 57 58 59 //ctor { while(n!=NULL) } 36 37 38 39 40 41 42 43 44 45 46 cout << n->value << endl; n=n->next; 60 61 62 63 64 65 66 67 68 69 70 71 void LinkedList::insertAtTheFront (Node** head, int newValue) { Node newNode = new Node(); newNode->value=newValue; newNode->next="head; *head=newNode; } void LinkedList::insertAt The End (Node** head, int newValue) { Node* newNode= new Node(); newNode->value = newValue; newNode->next = NULL; if (*head = NULL) { *head=newNode; } Node" last=*head; while(last->next!=NULL) last-last->next; { } return; last->next=newNode; } void LinkedList::insertAfter (Node* previous, int newValue) { if(previous ==NULL) { cout << "Previous node cannot be NULL."; return; } Node* newNode = new Node(); newNode->value=newValue; newNode->next-previous->next; previous->next=newNode; 73 int main() 74 { 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 } Node head = new Node(); Node* second = new Node(); Node* third new Node(); head->value=1; head->next=second; second->value=2; second->next=third; third->value=4; third->next=NULL; LinkedList 11; 11.insertAtTheFront (&head, -1); 11.insertAtThe End (&head, 5); 11.insertAfter (head, 0); 11.insertAfter (second, 3); 11.printLinkedList (head); return 0;
Expert Solution
steps

Step by step

Solved in 2 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY