Question: Lab_3: Objective: Experiment with Lists, Stacks, and Queues: Simulate an OS task manager Assignment: Using the startup code, implement the following: 1-Create List L1 of

Lab_3: Objective: Experiment with Lists, Stacks, and Queues: Simulate an OS task manager

Assignment:

Using the startup code, implement the following:

1-Create List L1 of 10 elements (task IDs), e.g. L1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;

2-Insert a new list element in between (at every other element), such as: 1,100, 2,200, 3,300, 4,400, ... 10,1000;

Simulate a new CPU core assignment:

3-Create another List L2, and extract the newly inserted elements into this new list L2

i.e. L1 should go back to the original list: L1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

L2 should be: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000

Start executing:

4-Create a Queue Q1 by extracting L1, and inserting L2 elements: i.e. Q should start with: 1,2,3, ... 10, and (10, 20 ... 100) will be inserted

Q1=1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000

Label tasks as finished with the possibility of revisiting a task, such as:

5-Create a Stack S1 which by deleting the elements of Q1 and inserting them in L1

6-Pop out all elements of the Stack, i.e. should end up with an empty stack

Extra credit: Simulate a re-executed task, i.e. Pop out a task out of the Stack and reinsert, this simulate a failed task.

7-Verify the functionality and capture the results in a report form.

List.h

Lab_3: Objective: Experiment with Lists, Stacks, and Queues: Simulate an OS task

manager Assignment: Using the startup code, implement the following: 1-Create List L1

of 10 elements (task IDs), e.g. L1 = 1, 2, 3, 4,

5, 6, 7, 8, 9, 10; 2-Insert a new list element in

between (at every other element), such as: 1,100, 2,200, 3,300, 4,400, ...

10,1000; Simulate a new CPU core assignment: 3-Create another List L2, and

main.cpp

#include "List.h" #include #include

using namespace std;

template

class Stack { public: bool isEmpty() const { return theList.empty(); } const Object& top() const { return theList.front(); } void push(const Object& x) { theList.push_front(x); } void pop(Object& x) { x = theList.front(); theList.pop_front(); } private: List theList; };

template class Queue { public: bool isEmpty() const { return theList.empty(); } const Object& getFront() const { return theList.front(); } void enqueue(const Object& x) { theList.push_back(x); } void dequeue(Object& x) { x = theList.front(); theList.pop_front(); } private: List theList; };

int main() { int i; const int N = 10;

List L1; Stack S1; Queue Q1;

List::iterator node; //Variable to keep track of the position as we traverse

// List Section example: //Q1: Create List L1 of 10 elements, e.g. L1 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10; // create the list array as a starting point: for (i = N; i > 0; --i) { L1.push_front(i); }

// show L1 with an iterator cout

// Stack Section example: // // Stack to be created per the above assignment requirment cout = 0; --i) { S1.push(i); cout

while (!S1.isEmpty()) { cout

// Queue section, to be created per the above assignment requirment // //

return 0; }

please answer with C++ code thank you!

private: int theSize; Node *head; Node *tail; void init( ) \{ theSize =0; head = new Node; tail = new Node; head >next = tail; tail presy = head; \} \}; \#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!