Maharashtra HSC Computer Science (Bifocal) study materials
Maharashtra HSC Computer Science (Bifocal) study resources

Maharashtra HSC Computer Science (Bifocal): Data Structures and File Handling

Maharashtra HSC Computer Science (Bifocal) · Work through your exam, one topic at a time.

All guide sections

Data Structures and File Handling

Scope

Data Structures and File Handling covers how data is stored and operated on: arrays, stacks, queues, linked lists, and stream-based file input/output. Questions ask for operation sequences, LIFO/FIFO behaviour, and correct file open/close logic.

Core rules

  • An array stores same-type elements in contiguous memory; access is by index and size is fixed at declaration.
  • A stack is LIFO: push adds at the top, pop removes from the top. Underflow means popping an empty stack; overflow means pushing beyond capacity.
  • A queue is FIFO: enqueue at the rear, dequeue from the front. A circular queue reuses freed slots.
  • A linked list stores nodes with data and a link; insertion/deletion can be efficient but traversal is sequential.
  • File streams: open with a mode such as read, write or append; check open success; process until end-of-file; always close.

Worked example

Start with an empty stack. Push A → top A. Push B → top B. Push C → top C. Pop returns C, leaving top B. Push D → top D. Pop returns D, leaving stack B, A with top B. The popped order is C then D. Reasoning: each pop removes only the most recently pushed item, so the last pushed among the current items is the first removed.

Traps

Do not confuse stack top with queue front. Do not use an array index equal to size. In files, eof-controlled loops can process the last record twice if the read is not checked immediately. Forgetting close may lose buffered data.