File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
CompetitiveProgramming/HackerEarth/DataStructures/Queue Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # You have to perform N operations on a queue of the following types: E x : Enqueue x in the queue and
2+ # print the new size of the queue. D : Dequeue from the queue and print the element that is deleted and
3+ # the new size of the queue separated by a space. If there is no element in the queue, then print −1 in
4+ # place of the deleted element.
5+ #
6+ # Input format
7+ # First line: N
8+ # Next N lines: One of the above operations
9+ #
10+ # Output format
11+ # Enqueue operation: Print the new size of the queue
12+ # Dequeue operation: Print two integers, the deleted element and the new size of the queue. If the queue is
13+ # empty, print −1 and the new size of the queue.
14+ #
15+ # Constraints
16+ # 1≤N≤100
17+ # 1≤x≤100
18+ #
19+ # SAMPLE INPUT
20+ # 5
21+ # E 2
22+ # D
23+ # D
24+ # E 3
25+ # D
26+ #
27+ # SAMPLE OUTPUT
28+ # 1
29+ # 2 0
30+ # -1 0
31+ # 1
32+ # 3 0
33+
34+ def enqueue (myList , element ):
35+ myList .insert (0 , element )
36+
37+ def dequeue (myList ):
38+ if len (myList ) > 0 :
39+ return myList .pop ()
40+ else :
41+ return - 1
42+
43+ myList = []
44+
45+ for _ in range (int (input ())):
46+ userInput = input ().split ()
47+ if userInput [0 ] == 'E' :
48+ enqueue (myList , int (userInput [1 ]))
49+ print (len (myList ))
50+ else :
51+ deleted = dequeue (myList )
52+ print (deleted , len (myList ))
You can’t perform that action at this time.
0 commit comments