{"id":"96e39eee-953e-4db7-9d4b-44ab166b2795","name":"Normal Queue","description":"1. You are required to complete the code of our CustomQueue class. The class should mimic the behaviour of a Queue and implement FIFO semantic.\r\n2. Here is the list of functions that you are supposed to complete\r\n 2.1. add -> Should accept new data if there is space available in the underlying \r\n array or print \"Queue overflow\" otherwise.\r\n 2.2. remove -> Should remove and return value according to FIFO, if available or \r\n print \"Queue underflow\" otherwise and return -1.\r\n 2.3. peek -> Should return value according to FIFO, if available or print \"Queue \r\n underflow\" otherwise and return -1.\r\n 2.4. size -> Should return the number of elements available in the queue.\r\n 2.5. display -> Should print the elements of queue in FIFO manner (space- \r\n separated) ending with a line-break.\r\n3. Input and Output is managed for you.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"None","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <exception>\nusing namespace std;\n\nclass CustomQueue{\n public:\n int *arr;\n int sizeQ;\n int front;\n int arrSize;\n \n CustomQueue(int cap){\n sizeQ = 0;\n front = 0;\n arr = new int[cap];\n arrSize = cap;\n }\n \n int size(){\n // write your code here\n }\n \n void add(int data){\n // write your code here\n }\n\n int peek(){\n // write your code here\n }\n\n int remove(){\n // write your code here\n }\n \n void display() {\n // write your code here\n }\n};\n\nint main(){\n int n;\n cin>>n;\n CustomQueue q(n);\n string str;\n cin>>str;\n \n while(str!=\"quit\"){\n if(str==\"add\"){\n int val;\n cin>>val;\n q.add(val);\n }\n else if(str==\"remove\"){\n int val = q.remove();\n if(val != -1){\n cout<<val<<endl;\n }\n }\n else if(str==\"peek\"){\n int val = q.peek();\n if(val != -1){\n cout<<val<<endl;\n }\n }\n else if(str==\"size\"){\n cout<<q.size()<<endl;\n }\n else if(str==\"display\"){\n q.display();\n }\n cin>>str;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static class CustomQueue {\r\n int[] data;\r\n int front;\r\n int size;\r\n\r\n public CustomQueue(int cap) {\r\n data = new int[cap];\r\n front = 0;\r\n size = 0;\r\n }\r\n\r\n int size() {\r\n // write ur code here\r\n }\r\n\r\n void display() {\r\n // write ur code here\r\n }\r\n\r\n void add(int val) {\r\n // write ur code here\r\n }\r\n\r\n int remove() {\r\n // write ur code here\r\n }\r\n\r\n int peek() {\r\n // write ur code here\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n CustomQueue qu = new CustomQueue(n);\r\n\r\n String str = br.readLine();\r\n while(str.equals(\"quit\") == false){\r\n if(str.startsWith(\"add\")){\r\n int val = Integer.parseInt(str.split(\" \")[1]);\r\n qu.add(val);\r\n } else if(str.startsWith(\"remove\")){\r\n int val = qu.remove();\r\n if(val != -1){\r\n System.out.println(val);\r\n }\r\n } else if(str.startsWith(\"peek\")){\r\n int val = qu.peek();\r\n if(val != -1){\r\n System.out.println(val);\r\n }\r\n } else if(str.startsWith(\"size\")){\r\n System.out.println(qu.size());\r\n } else if(str.startsWith(\"display\")){\r\n qu.display();\r\n }\r\n str = br.readLine();\r\n }\r\n }\r\n}"},"python":{"code":"class CustomQueue:\n def __init__(self, cap):\n self.sizeQ = 0;\n self.front = 0;\n self.arrLen = cap;\n self.arr = [0] * self.arrLen;\n \n def size(self):\n # write your code here\n \n def add(self, data):\n # write your code here\n \n def peek(self):\n # write your code here\n\n def remove(self):\n # write your code here\n \n def display(self):\n # write your code here\n \ndef main():\n n = int(input());\n q = CustomQueue(n);\n sr = input().strip();\n srP = sr.split(\" \");\n \n while(srP[0]!=\"quit\"):\n \n if(srP[0].strip()==\"add\"):\n q.add(int(srP[1]));\n \n elif(srP[0].strip()==\"remove\"):\n val = q.remove();\n if(val != -1):\n print(val);\n \n elif(srP[0].strip()==\"peek\"):\n val = q.peek();\n if(val != -1):\n print(val);\n \n elif(srP[0].strip()==\"size\"):\n print(q.size());\n \n elif(srP[0].strip()==\"display\"):\n q.display();\n \n sr = input().strip();\n srP = sr.split(\" \");\n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\nadd 10\r\ndisplay\r\nadd 20\r\ndisplay\r\nadd 30\r\ndisplay\r\nadd 40\r\ndisplay\r\nadd 50\r\ndisplay\r\nadd 60\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\nquit","sampleOutput":"10 \r\n10 20 \r\n10 20 30 \r\n10 20 30 40 \r\n10 20 30 40 50 \r\nQueue overflow\r\n10 20 30 40 50 \r\n10\r\n10\r\n20 30 40 50 \r\n20\r\n20\r\n30 40 50 \r\n30\r\n30\r\n40 50 \r\n40\r\n40\r\n50 \r\n50\r\n50\r\n\r\nQueue underflow\r\nQueue underflow","questionVideo":"https://www.youtube.com/embed/NdaEQPlH1vE","hints":[],"associated":[{"id":"4e426810-d7ba-4e2d-a46e-f14c73ddb9a7","name":"CustomQueue class has a parameter called ?(Q- Normal Queue)","slug":"customqueue-class-has-a-parameter-called-q-normal-queue","type":4},{"id":"74880c27-ea9f-420b-882f-d64011746613","name":"A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?(Q- Nnormal Queue)","slug":"a-data-structure-in-which-elements-can-be-inserted-or-deleted-at-from-both-ends-but-not-in-the-middle-is-q-nnormal-queue","type":4},{"id":"b518f960-7184-4f38-8e78-01a9591de2c3","name":"What time does both insertion and deletion of an element takes ?(Q- Normal Queue)","slug":"what-time-does-both-insertion-and-deletion-of-an-element-takes-q-normal-queue","type":4},{"id":"d830a7d7-ba1f-42d0-963b-d7be5fbee091","name":"A queue is a ?(Q- Normal Queue)","slug":"a-queue-is-a-q-normal-queue","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"49b6b7ce-21f7-4f89-a842-ff5c47155be3","name":"Normal Queue","slug":"normal-queue","type":1}],"next":{"id":"fa76c7e5-a165-4e8d-b34a-1c7b1ad316b4","name":"Normal Queue","type":3,"slug":"normal-queue"},"prev":{"id":"69dfece2-1f77-4dee-97e6-11b1e4369a7a","name":"Queues Intro and usage","type":0,"slug":"queues-intro-and-usage"}}}

Normal Queue

1. You are required to complete the code of our CustomQueue class. The class should mimic the behaviour of a Queue and implement FIFO semantic. 2. Here is the list of functions that you are supposed to complete 2.1. add -> Should accept new data if there is space available in the underlying array or print "Queue overflow" otherwise. 2.2. remove -> Should remove and return value according to FIFO, if available or print "Queue underflow" otherwise and return -1. 2.3. peek -> Should return value according to FIFO, if available or print "Queue underflow" otherwise and return -1. 2.4. size -> Should return the number of elements available in the queue. 2.5. display -> Should print the elements of queue in FIFO manner (space- separated) ending with a line-break. 3. Input and Output is managed for you.

{"id":"96e39eee-953e-4db7-9d4b-44ab166b2795","name":"Normal Queue","description":"1. You are required to complete the code of our CustomQueue class. The class should mimic the behaviour of a Queue and implement FIFO semantic.\r\n2. Here is the list of functions that you are supposed to complete\r\n 2.1. add -> Should accept new data if there is space available in the underlying \r\n array or print \"Queue overflow\" otherwise.\r\n 2.2. remove -> Should remove and return value according to FIFO, if available or \r\n print \"Queue underflow\" otherwise and return -1.\r\n 2.3. peek -> Should return value according to FIFO, if available or print \"Queue \r\n underflow\" otherwise and return -1.\r\n 2.4. size -> Should return the number of elements available in the queue.\r\n 2.5. display -> Should print the elements of queue in FIFO manner (space- \r\n separated) ending with a line-break.\r\n3. Input and Output is managed for you.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"None","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <exception>\nusing namespace std;\n\nclass CustomQueue{\n public:\n int *arr;\n int sizeQ;\n int front;\n int arrSize;\n \n CustomQueue(int cap){\n sizeQ = 0;\n front = 0;\n arr = new int[cap];\n arrSize = cap;\n }\n \n int size(){\n // write your code here\n }\n \n void add(int data){\n // write your code here\n }\n\n int peek(){\n // write your code here\n }\n\n int remove(){\n // write your code here\n }\n \n void display() {\n // write your code here\n }\n};\n\nint main(){\n int n;\n cin>>n;\n CustomQueue q(n);\n string str;\n cin>>str;\n \n while(str!=\"quit\"){\n if(str==\"add\"){\n int val;\n cin>>val;\n q.add(val);\n }\n else if(str==\"remove\"){\n int val = q.remove();\n if(val != -1){\n cout<<val<<endl;\n }\n }\n else if(str==\"peek\"){\n int val = q.peek();\n if(val != -1){\n cout<<val<<endl;\n }\n }\n else if(str==\"size\"){\n cout<<q.size()<<endl;\n }\n else if(str==\"display\"){\n q.display();\n }\n cin>>str;\n }\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static class CustomQueue {\r\n int[] data;\r\n int front;\r\n int size;\r\n\r\n public CustomQueue(int cap) {\r\n data = new int[cap];\r\n front = 0;\r\n size = 0;\r\n }\r\n\r\n int size() {\r\n // write ur code here\r\n }\r\n\r\n void display() {\r\n // write ur code here\r\n }\r\n\r\n void add(int val) {\r\n // write ur code here\r\n }\r\n\r\n int remove() {\r\n // write ur code here\r\n }\r\n\r\n int peek() {\r\n // write ur code here\r\n }\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n int n = Integer.parseInt(br.readLine());\r\n CustomQueue qu = new CustomQueue(n);\r\n\r\n String str = br.readLine();\r\n while(str.equals(\"quit\") == false){\r\n if(str.startsWith(\"add\")){\r\n int val = Integer.parseInt(str.split(\" \")[1]);\r\n qu.add(val);\r\n } else if(str.startsWith(\"remove\")){\r\n int val = qu.remove();\r\n if(val != -1){\r\n System.out.println(val);\r\n }\r\n } else if(str.startsWith(\"peek\")){\r\n int val = qu.peek();\r\n if(val != -1){\r\n System.out.println(val);\r\n }\r\n } else if(str.startsWith(\"size\")){\r\n System.out.println(qu.size());\r\n } else if(str.startsWith(\"display\")){\r\n qu.display();\r\n }\r\n str = br.readLine();\r\n }\r\n }\r\n}"},"python":{"code":"class CustomQueue:\n def __init__(self, cap):\n self.sizeQ = 0;\n self.front = 0;\n self.arrLen = cap;\n self.arr = [0] * self.arrLen;\n \n def size(self):\n # write your code here\n \n def add(self, data):\n # write your code here\n \n def peek(self):\n # write your code here\n\n def remove(self):\n # write your code here\n \n def display(self):\n # write your code here\n \ndef main():\n n = int(input());\n q = CustomQueue(n);\n sr = input().strip();\n srP = sr.split(\" \");\n \n while(srP[0]!=\"quit\"):\n \n if(srP[0].strip()==\"add\"):\n q.add(int(srP[1]));\n \n elif(srP[0].strip()==\"remove\"):\n val = q.remove();\n if(val != -1):\n print(val);\n \n elif(srP[0].strip()==\"peek\"):\n val = q.peek();\n if(val != -1):\n print(val);\n \n elif(srP[0].strip()==\"size\"):\n print(q.size());\n \n elif(srP[0].strip()==\"display\"):\n q.display();\n \n sr = input().strip();\n srP = sr.split(\" \");\n \nmain()"}},"points":10,"difficulty":"easy","sampleInput":"5\r\nadd 10\r\ndisplay\r\nadd 20\r\ndisplay\r\nadd 30\r\ndisplay\r\nadd 40\r\ndisplay\r\nadd 50\r\ndisplay\r\nadd 60\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\ndisplay\r\npeek\r\nremove\r\nquit","sampleOutput":"10 \r\n10 20 \r\n10 20 30 \r\n10 20 30 40 \r\n10 20 30 40 50 \r\nQueue overflow\r\n10 20 30 40 50 \r\n10\r\n10\r\n20 30 40 50 \r\n20\r\n20\r\n30 40 50 \r\n30\r\n30\r\n40 50 \r\n40\r\n40\r\n50 \r\n50\r\n50\r\n\r\nQueue underflow\r\nQueue underflow","questionVideo":"https://www.youtube.com/embed/NdaEQPlH1vE","hints":[],"associated":[{"id":"4e426810-d7ba-4e2d-a46e-f14c73ddb9a7","name":"CustomQueue class has a parameter called ?(Q- Normal Queue)","slug":"customqueue-class-has-a-parameter-called-q-normal-queue","type":4},{"id":"74880c27-ea9f-420b-882f-d64011746613","name":"A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?(Q- Nnormal Queue)","slug":"a-data-structure-in-which-elements-can-be-inserted-or-deleted-at-from-both-ends-but-not-in-the-middle-is-q-nnormal-queue","type":4},{"id":"b518f960-7184-4f38-8e78-01a9591de2c3","name":"What time does both insertion and deletion of an element takes ?(Q- Normal Queue)","slug":"what-time-does-both-insertion-and-deletion-of-an-element-takes-q-normal-queue","type":4},{"id":"d830a7d7-ba1f-42d0-963b-d7be5fbee091","name":"A queue is a ?(Q- Normal Queue)","slug":"a-queue-is-a-q-normal-queue","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"9847c2b3-e3ad-4b1c-97d1-00206b1be68d","name":"Stacks And Queues For Beginners","slug":"stacks-and-queues-for-beginners","type":0},{"id":"49b6b7ce-21f7-4f89-a842-ff5c47155be3","name":"Normal Queue","slug":"normal-queue","type":1}],"next":{"id":"fa76c7e5-a165-4e8d-b34a-1c7b1ad316b4","name":"Normal Queue","type":3,"slug":"normal-queue"},"prev":{"id":"69dfece2-1f77-4dee-97e6-11b1e4369a7a","name":"Queues Intro and usage","type":0,"slug":"queues-intro-and-usage"}}}
plane

Editor


Loading...

Normal Queue

easy

1. You are required to complete the code of our CustomQueue class. The class should mimic the behaviour of a Queue and implement FIFO semantic. 2. Here is the list of functions that you are supposed to complete 2.1. add -> Should accept new data if there is space available in the underlying array or print "Queue overflow" otherwise. 2.2. remove -> Should remove and return value according to FIFO, if available or print "Queue underflow" otherwise and return -1. 2.3. peek -> Should return value according to FIFO, if available or print "Queue underflow" otherwise and return -1. 2.4. size -> Should return the number of elements available in the queue. 2.5. display -> Should print the elements of queue in FIFO manner (space- separated) ending with a line-break. 3. Input and Output is managed for you.

Constraints

None

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

5 add 10 display add 20 display add 30 display add 40 display add 50 display add 60 display peek remove display peek remove display peek remove display peek remove display peek remove display peek remove quit

Sample Output

10 10 20 10 20 30 10 20 30 40 10 20 30 40 50 Queue overflow 10 20 30 40 50 10 10 20 30 40 50 20 20 30 40 50 30 30 40 50 40 40 50 50 50 Queue underflow Queue underflow

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode