Stacks & Queues in list

Sponsor Area

Question
CBSEENCO12011593

Evaluate the following Postfix notation of expression:
4,2,*,22,5,6,+,/,-

Solution

Element Stack Contents  
4 4
2 4,2
* 8
22 8, 22
5 8, 22, 5
6 8, 22, 5, 6
+ 8, 22, 11
/ 8, 2
- 6

Sponsor Area

Question
CBSEENCO12011594

Differentiate between file modes r+ and rb+ with respect to Python.

Solution

Difference b/w r+ and rb+ with respect to Python

r+   rb+ 
r+ Opens a file for both reading and writing. The file pointer placed at the beginning of the file. rb+ Opens a file for both reading and writing in binary format. The file pointer placed at the beginning of the file.

Question
CBSEENCO12011641

Evaluate the following postfix notation of expression. Show status of the stack after every operation.
22,11,/,14,10,,+,5,2

Solution

Element Stack
22 22
11 22, 11
/ 2
14 2,14
10 2,14,10
- 2,4
+ 6
5 6,5
- 1    

Question
CBSEENCO12011642

Write a statement in Python to perform the following operations:

  • To open a text file “BOOK.TXT” in read mode
  • To open a text file “BOOK.TXT” in write mode

Solution

f1 = open('BOOK.TXT','r')
f2 = open('BOOK.TXT','w')