emoves the element from the front of the queue and in turn, returns the element being dequeued or removed. In e element being kept at the front of the queue. In case the queue is empty, it returns -1. = e size of the queue at any given instance of time. = boolean value indicating whether the queue is empty or not. rformed on the Stack: ed by an integer 1): Enqueues an integer data to the queue. ed by an integer 2): Dequeues the data kept at the front of the queue and returns it to the caller. ed by an integer 3): Fetches and returns the data being kept at the front of the queue but doesn't remove it,

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
1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List.
2 The data members should be private.
3
You need to implement the following public functions:
4
1. Constructor:
5 It initialises the data members as required.
6
7
8
2. enqueue(data) :
This function should take one argument of type integer. It enqueues the element into the queue and returns nothing.
3. dequeue():
It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r
4. front ():
10
11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1.
12 5. getSize():
13
It returns the size of the queue at any given instance of time.
14 6. 1sEmpty():
15
It returns a boolean value indicating whether the queue is empty or not.
16 Operations Performed on the Stack:
17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue.
18
19
Query-2 (Denoted by an integer 2): Dequeues the data kept at the front of the queue and returns it to the caller.
20
21
Query-3 (Denoted by an integer 3): Fetches and returns the data being kept at the front of the queue but doesn't remove it, unlike the dequeue function.
22
23
Query-4(Denoted by an integer 4): Returns the current size of the queue.
24
25
Query-5(Denoted by an integer 5): Returns a boolean value denoting whether the queue is empty or not.
26
Input Format:
27
The first line contains an integer 'q' which denotes the number of queries to be run against each operation on the queue.
Then the test cases follow.
28
29
30
31
32
9
Every 'q' lines represent an operation that needs to be performed.
33
For the enqueue operation, the input line will contain two integers separated by a single space, representing the type of the operation in integer and t
For the rest of the operations on the queue, the input line will contain only one integer value, representing the query being performed on the queue.
35 Output Format:
34
36
For Query-1, you do not need to return anything.
37 For Query-2, prints the data being dequeued from the queue.
38 For Query-3, prints the data kept on the front of the queue.
39 For Query-4, prints the current size of the queue.
40
For Query-5, prints 'true' or 'false' (without quotes).
41
42
43
44
45
46
47
48
Output for every query will be printed in a separate line.
Note:
You are not required to print anything explicitly. It has already been taken care of. Just implement the functions.
Constraints:
1<q < 10^5
1 <= x <= 5
-2^31 <= data <= 2^31-1 and data != -1
49
50
Where 'q' is the total number of queries being performed on the queue, 'x' is the range for every query and data represents the integer pushed into the
51
52
Time Limit: 1 second
53 Sample Input 1:
54
7
1 17
55
56
57
58 2
59 2
1 23
1 11
60 2
61 2
62 Sample Output 1:
63 17
64 23
65 11
66
-1
67 Sample Input 2:
68
3
69 2
70 1.10
71 4
72
73
Sample Output 2:
Transcribed Image Text:1 Implement a Queue Data Structure specifically to store integer data using a Singly Linked List. 2 The data members should be private. 3 You need to implement the following public functions: 4 1. Constructor: 5 It initialises the data members as required. 6 7 8 2. enqueue(data) : This function should take one argument of type integer. It enqueues the element into the queue and returns nothing. 3. dequeue(): It dequeues/removes the element from the front of the queue and in turn, returns the element being dequeued or removed. In case the queue is empty, it r 4. front (): 10 11 It returns the element being kept at the front of the queue. In case the queue is empty, it returns -1. 12 5. getSize(): 13 It returns the size of the queue at any given instance of time. 14 6. 1sEmpty(): 15 It returns a boolean value indicating whether the queue is empty or not. 16 Operations Performed on the Stack: 17 Query-1 (Denoted by an integer 1): Enqueues an integer data to the queue. 18 19 Query-2 (Denoted by an integer 2): Dequeues the data kept at the front of the queue and returns it to the caller. 20 21 Query-3 (Denoted by an integer 3): Fetches and returns the data being kept at the front of the queue but doesn't remove it, unlike the dequeue function. 22 23 Query-4(Denoted by an integer 4): Returns the current size of the queue. 24 25 Query-5(Denoted by an integer 5): Returns a boolean value denoting whether the queue is empty or not. 26 Input Format: 27 The first line contains an integer 'q' which denotes the number of queries to be run against each operation on the queue. Then the test cases follow. 28 29 30 31 32 9 Every 'q' lines represent an operation that needs to be performed. 33 For the enqueue operation, the input line will contain two integers separated by a single space, representing the type of the operation in integer and t For the rest of the operations on the queue, the input line will contain only one integer value, representing the query being performed on the queue. 35 Output Format: 34 36 For Query-1, you do not need to return anything. 37 For Query-2, prints the data being dequeued from the queue. 38 For Query-3, prints the data kept on the front of the queue. 39 For Query-4, prints the current size of the queue. 40 For Query-5, prints 'true' or 'false' (without quotes). 41 42 43 44 45 46 47 48 Output for every query will be printed in a separate line. Note: You are not required to print anything explicitly. It has already been taken care of. Just implement the functions. Constraints: 1<q < 10^5 1 <= x <= 5 -2^31 <= data <= 2^31-1 and data != -1 49 50 Where 'q' is the total number of queries being performed on the queue, 'x' is the range for every query and data represents the integer pushed into the 51 52 Time Limit: 1 second 53 Sample Input 1: 54 7 1 17 55 56 57 58 2 59 2 1 23 1 11 60 2 61 2 62 Sample Output 1: 63 17 64 23 65 11 66 -1 67 Sample Input 2: 68 3 69 2 70 1.10 71 4 72 73 Sample Output 2:
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
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