Exercise: Stack and Queue implemented by a linked list.

Assuming an algorithmic linked list with the following behaviour:

addFirst(element data)

addLast(element data)

element removeFirst()

element removeLast()

boolean isEmpty()

  1. Write algorithms to implement a stack using the functions alone,
    • push (element data)
    • element pop ()
    • element peek() (Hint: get the data out then put it back in)

  2. Write algorithms to implement a Queue using the functions alone,
    • enqueue (element data) //add
    • element dequeue () //remove

© 2023  Vedesh Kungebeharry. All rights reserved. 

How to download an attachment from a google classroom post (Naparima College)

See the short demo on how to download an attachment from a google classroom post (Naparima College)

Steps:

  1. Click on the attachment
  2. click the 3 vertical dots and choose “Open in new window”
  3. The download button now becomes available in the new window, Click on it.
  4. The file will be automatically downloaded. To see your recent downloads , press Ctrl+J

© 2023  Vedesh Kungebeharry. All rights reserved. 

The Main Purpose Of the Operating system

The hardware components of a computer will not operate on it’s own due to  the nature of it’s design. 

Computers are designed to be instructed by software.

The operating system is the software just above the firmware level which provides a user interface to the user so that they may indirectly interact or command the hardware. The OS manages hardware resources that must be used by the various running processes of the computer system.

Discussion:

Consider the feedback loop where the user attempts to print a word processing document

-Graphics on screen

-application software

-what happens if 2 apps need to print at the same time?

Thinking about the operating system as a Resource Manager

The OS mainly manages  :

  • Memory
  • Input and output operations (I/O operations)
  • The processor
  • The user interface

© 2023  Vedesh Kungebeharry. All rights reserved. 

2022 U2 Q1

Part a)

The main difference between a stack and a queue is how data is inserted and removed from each of them. In a stack, the last element inserted is the first to be removed as compared to a queue where the first element inserted is the first to be removed.

Part b) i)

The enqueue(element) adds an element to the end of  the list of elements which represent the queue. If the list of elements is empty, it adds it at the first location or head of the queue.

Part b) ii)

The dequeue(element) removes an element to the front of  the list of elements which represent the queue. If the list of elements is empty, no element is removed.

Part c)

//Assumptions: The following state is used
#define MAX_SIZE 100
int stack[MAX_SIZE];
int top = -1;

void push(int *stack, int value) {
    if (top >= MAX_SIZE - 1) {
        // Stack is full
        printf("Stack is full, element was not added!\n");
        return;
    }
    top++;
    stack[top] = value;
}

© 2023  Vedesh Kungebeharry. All rights reserved.