CS301-lec08.ppt

Verified academic study resource for CS301 (Data Structures) under the Computer Science at Virtual University of Pakistan. This PPT document (Official Lecture Handouts & Highlighted Notes) covers Complete Course Handouts (Lectures 1 to 45) spanning approximately 450 pages across 8 curriculum modules, and is indexed for student examination review with instant in-browser preview and 100% free direct download.

Course
CS301 – Data Structures
Faculty
Computer Science
Format
PPT
Type
Handout
Coverage
Complete Course Handouts (Lectures 1 to 45)
Tags
SLIDES

Virtual University examiners construct 100% of objective MCQs and subjective marking schemes directly from the official CS301 handouts.

What this file covers — CS301 syllabus roadmap

  1. Core Architecture, Syntax & Primitive Data Structures — Lectures 1 to 6 (Pages 1 to 65). 15% Objective Marks (8–10 MCQs)
  2. Conditional Branching, Loops & Logical Control Flow — Lectures 7 to 12 (Pages 66 to 140). 18% Exam Marks (MCQs + 2-Mark Short Questions)
  3. Memory Management, Pointers, Arrays & Functions — Lectures 13 to 18 (Pages 141 to 215). 22% Exam Marks (High Yield for Midterms)
  4. Midterm Consolidation, Strings & Algorithm Synthesis — Lectures 19 to 22 (Pages 216 to 280). Midterm Exam Culmination (Lectures 1–22 Scope)
  5. Object-Oriented Paradigms: Classes & Data Abstraction — Lectures 23 to 29 (Pages 281 to 360). 16% Final-Term Marks (Core OO Concepts)
  6. Inheritance Hierarchies & Dynamic Polymorphism — Lectures 30 to 36 (Pages 361 to 435). 20% Final-Term Marks (Virtual Functions & V-Tables)
  7. Templates, Standard Library & Persistent File I/O — Lectures 37 to 41 (Pages 436 to 510). 14% Final-Term Marks (Generic Code & Streams)
  8. Final-Term Examination Dossier & Capstone Synthesis — Lectures 42 to 45 (Pages 511 to 585). Final-Term Exam Synthesis (Lectures 23–45 Scope)

Frequently asked questions

Where can I download CS301-lec08.ppt for free?

You can preview and download "CS301-lec08.ppt" (CS301 PPT, ~450 pages) directly from the MIHORA VU Study Library (https://study.mihora.tech/doc/cs301-lec08-ppt) with 100% free high-speed downloads and zero registration requirements.

What syllabus chapters and lectures are covered in this CS301 file?

This document covers Complete Course Handouts (Lectures 1 to 45) across 8 distinct lecture units (Lectures 1 to 6, Lectures 7 to 12, Lectures 13 to 18, Lectures 19 to 22, Lectures 23 to 29, Lectures 30 to 36, Lectures 37 to 41, Lectures 42 to 45), featuring comprehensive definitions, solved objective questions, and examiner marking rubrics.

What is the passing criteria for CS301 under the VU 20% Two-Half Rule?

Under official Virtual University regulations, students must score at least 20% in the First Half (Quizzes, Assignments, GDBs, and Midterm combined) AND independently at least 20% in the Final-Term examination paper. Scoring under 20% in the final exam results in an automatic F grade regardless of earlier marks.

Are CS301 solved past papers and handouts verified for 2026 exams?

Yes. All CS301 materials on MIHORA VU—including Moaaz, Waqar Siddhu, and team archives—are reviewed against the current VU syllabus to help students prepare for 2026 Midterm, Final-Term, and online quiz examinations.

Inside this file

Lecture No.08

Data Structures

Dr. Sohail Aslam

Converting Infix to Postfix
 Example: (A + B) * C
  symb          postfix   stack
  (  (
  A A           (
  + A           (+
  B AB          (+
  )  AB +
  *  AB +       *
  C AB + C *
     AB + C *

C++ Templates
 We need a stack of operands and a stack
  of operators.
 Operands can be integers and floating
  point numbers, even variables.
 Operators are single characters.
 We would have to create classes
  FloatStack and CharStack.
 Yet the internal workings of both classes is
  the same.

C++ Templates
 We can use C++ Templates to create a
  “template” of a stack class.
 Instantiate float stack, char stack, or stack
  for any type of element we want.

Stack using templates
                      Stack.h:
template <class T>
class Stack {
public:
    Stack();
    int empty(void); // 1=true, 0=false
    int push(T &); // 1=successful,0=stack overflow
    T pop(void);
    T peek(void);
    ~Stack();
private:
    int top;
    T* nodes;
};

Stack using templates
                  Stack.cpp
 #include <iostream.h>
 #include <stdlib.h>
 #include "Stack.cpp"

 #define MAXSTACKSIZE 50

 template <class T>
 Stack<T>::Stack()
 {
     top = -1;
     nodes = new T[MAXSTACKSIZE];
 }

Stack using templates
                  Stack.cpp
 template <class T>
 Stack<T>::~Stack()
 {
     delete nodes;
 }

 template <class T>
 int Stack<T>::empty(void)
 {
     if( top < 0 ) return 1;
     return 0;
 }

Stack using templates
                  Stack.cpp
 template <class T>
 int Stack<T>::push(T& x)
 {
     if( top < MAXSTACKSIZE ) {
         nodes[++top] = x;
         return 1;
     }
     cout << "stack overflow in push.\n";
     return 0;
 }

Stack using templates
                  Stack.cpp
 template <class T>
 T Stack<T>::pop(void)
 {
     T x;
     if( !empty() ) {
          x = nodes[top--];
          return x;
     }
     cout << "stack underflow in pop.\n";
     return x;
 }

Stack using templates
                     main.cpp
 #include "Stack.cpp"
 int main(int argc, char *argv[]) {
   Stack<int> intstack;
   Stack<char> charstack;
   int x=10, y=20;
   char c='C', d='D';

     intstack.push(x);   intstack.push(y);
     cout << "intstack: " << intstack.pop() << ", "
          << intstack.pop() << "\n";

     charstack.push(c); charstack.push(d);
     cout << "charstack: " << charstack.pop() << ",
     "
          << charstack.pop() << "\n";
 }

Function Call Stack
 Stacks play a key role in implementation
  of function calls in programming
  languages.
 In C++, for example, the “call stack” is
  used to pass function arguments and
  receive return values.
 The call stack is also used for “local
  variables”

Call Stack
 In GCC, a popular C/C++ compiler on Intel
  platform, stack entries are:

      n*4(%esp)    last argument
                      ……….
       8(%esp)    second argument
       4(%esp)      first argument
        (%esp)     return address    top

Call Stack
  Example: consider the function:

      int i_avg (int a, int b)
      {
        return (a + b) / 2;
      }

        # Stack layout on entry:
        #
        # 8(%esp) b
        # 4(%esp) a
        # (%esp) return address

Call Stack
  Example: consider the function:

      int i_avg (int a, int b)
      {
        return (a + b) / 2;
      }

    .globl _i_avg
    _i_avg:
        movl 4(%esp), %eax
        addl 8(%esp), %eax # Add the args
        sarl $1, %eax # Divide by 2
        ret # Return value is in %eax

Memory Organization
 When a program          Process 1
                          (browser)
  (.exe) is run, it is
                          Process 3
  loaded in memory. It     (word)
  becomes a process.
                          Process 4
 The process is given     (excel)
  a block of memory.      Process 2
 [Control-Alt-DEL]       (dev-c++)

                         Windows OS

Task Manager

Memory Organization
   Process 1
   (browser)            Code
   Process 3
    (word)            Static data

   Process 4            Stack
    (excel)
   Process 2
   (dev-c++)

  Windows OS            Heap

More CS301 files

All CS301 files · Midterm Prep 2026 · MCQs Bank