SlideShare a Scribd company logo
1 of 4
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
main.cpp
#include "List.h"
#include <stdlib.h>
#include <iostream>
using namespace std;
template <typename Object>
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<Object> theList;
};
template <typename Object>
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<Object> theList;
};
int main()
{
int i;
const int N = 10;
List<int> L1;
Stack<int> S1;
Queue<int> Q1;
List<int>::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 << "List L1 is:" << endl;
for (auto it = L1.begin(); it != L1.end(); ++it)
{
cout << *it << ' ';
}
// Stack Section example:
//
// Stack to be created per the above assignment requirment
cout << "nStack S1 is:" << endl;;
for (i = N - 1; i >= 0; --i)
{
S1.push(i);
cout << S1.top() << " " << endl;
}
while (!S1.isEmpty())
{
cout << S1.top() << endl;
S1.pop(i);
}
// 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

More Related Content

Similar to Lab_3- Objective- Experiment with Lists- Stacks- and Queues- Simulate.docx

I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
fantoosh1
 
Implementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docxImplementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docx
RyanEAcTuckern
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
ElNew2
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
shahidqamar17
 

Similar to Lab_3- Objective- Experiment with Lists- Stacks- and Queues- Simulate.docx (20)

The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
 
The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212The Ring programming language version 1.10 book - Part 30 of 212
The Ring programming language version 1.10 book - Part 30 of 212
 
I need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdfI need help with this code working Create another project and add yo.pdf
I need help with this code working Create another project and add yo.pdf
 
The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212The Ring programming language version 1.10 book - Part 43 of 212
The Ring programming language version 1.10 book - Part 43 of 212
 
Implementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docxImplementation File- -------------------------------------------------.docx
Implementation File- -------------------------------------------------.docx
 
The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196The Ring programming language version 1.7 book - Part 37 of 196
The Ring programming language version 1.7 book - Part 37 of 196
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
Programming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdfProgramming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
 
The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185The Ring programming language version 1.5.4 book - Part 22 of 185
The Ring programming language version 1.5.4 book - Part 22 of 185
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdfComplete a C++ class implementation for a linked-list of sorted (asc.pdf
Complete a C++ class implementation for a linked-list of sorted (asc.pdf
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 

More from rennaknapp

Json File - { -student_id-- 101- -first_name-- -James--.docx
Json File -   {     -student_id-- 101-     -first_name-- -James--.docxJson File -   {     -student_id-- 101-     -first_name-- -James--.docx
Json File - { -student_id-- 101- -first_name-- -James--.docx
rennaknapp
 
John plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docxJohn plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docx
rennaknapp
 

More from rennaknapp (20)

Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docx
 
Land use changes and changing climatic conditions caused by human acti.docx
Land use changes and changing climatic conditions caused by human acti.docxLand use changes and changing climatic conditions caused by human acti.docx
Land use changes and changing climatic conditions caused by human acti.docx
 
Kimberly had to come up With a whictue data collection and analysis pr.docx
Kimberly had to come up With a whictue data collection and analysis pr.docxKimberly had to come up With a whictue data collection and analysis pr.docx
Kimberly had to come up With a whictue data collection and analysis pr.docx
 
Korb et al- (2000) obtained blood samples extracted fom patients infec.docx
Korb et al- (2000) obtained blood samples extracted fom patients infec.docxKorb et al- (2000) obtained blood samples extracted fom patients infec.docx
Korb et al- (2000) obtained blood samples extracted fom patients infec.docx
 
keep it simple pls Create a project named labExamCCCS221 containing fo.docx
keep it simple pls Create a project named labExamCCCS221 containing fo.docxkeep it simple pls Create a project named labExamCCCS221 containing fo.docx
keep it simple pls Create a project named labExamCCCS221 containing fo.docx
 
l Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
l   Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docxl   Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
l Question 4 1 pts Gatekeeper tumor suppressor genes--- Encode prote.docx
 
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docxL0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
L0-4 During 2022- Jenny- age 14- lives in a household with her father-.docx
 
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docxL0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
L0-7 In 2022- Jack- age 12 - has interest income of $4-900 on funds he.docx
 
Kyle is a student with an emotional behavioral disorder- He has also b.docx
Kyle is a student with an emotional behavioral disorder- He has also b.docxKyle is a student with an emotional behavioral disorder- He has also b.docx
Kyle is a student with an emotional behavioral disorder- He has also b.docx
 
Json File - { -student_id-- 101- -first_name-- -James--.docx
Json File -   {     -student_id-- 101-     -first_name-- -James--.docxJson File -   {     -student_id-- 101-     -first_name-- -James--.docx
Json File - { -student_id-- 101- -first_name-- -James--.docx
 
Make a concept map that shows the hierarchical relationship between th.docx
Make a concept map that shows the hierarchical relationship between th.docxMake a concept map that shows the hierarchical relationship between th.docx
Make a concept map that shows the hierarchical relationship between th.docx
 
Jordan and Alyssa are saving for their daughter Taylor's college educa.docx
Jordan and Alyssa are saving for their daughter Taylor's college educa.docxJordan and Alyssa are saving for their daughter Taylor's college educa.docx
Jordan and Alyssa are saving for their daughter Taylor's college educa.docx
 
John receives $3-400 from an investment at the beginning of every half.docx
John receives $3-400 from an investment at the beginning of every half.docxJohn receives $3-400 from an investment at the beginning of every half.docx
John receives $3-400 from an investment at the beginning of every half.docx
 
Many documents use a specific format for a person's name- Write a prog.docx
Many documents use a specific format for a person's name- Write a prog.docxMany documents use a specific format for a person's name- Write a prog.docx
Many documents use a specific format for a person's name- Write a prog.docx
 
Many crimes- like embezzlement- have definite trends- The demographic.docx
Many crimes- like embezzlement- have definite trends- The demographic.docxMany crimes- like embezzlement- have definite trends- The demographic.docx
Many crimes- like embezzlement- have definite trends- The demographic.docx
 
Management The consequences of unresolved conflict often have devastat.docx
Management The consequences of unresolved conflict often have devastat.docxManagement The consequences of unresolved conflict often have devastat.docx
Management The consequences of unresolved conflict often have devastat.docx
 
Make a star field as in Star Trek (the original series)- like MS's.docx
Make a star field as in Star Trek (the original series)- like  MS's.docxMake a star field as in Star Trek (the original series)- like  MS's.docx
Make a star field as in Star Trek (the original series)- like MS's.docx
 
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docxMAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
MAKE a CONCEPT MAP illustrating how glycolysis- the Krebs-Citric acid.docx
 
John plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docxJohn plans to add a new operation Peek to the stackADT- This new opera.docx
John plans to add a new operation Peek to the stackADT- This new opera.docx
 
John is a part of a team that has been gathered temporarily to develop.docx
John is a part of a team that has been gathered temporarily to develop.docxJohn is a part of a team that has been gathered temporarily to develop.docx
John is a part of a team that has been gathered temporarily to develop.docx
 

Recently uploaded

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 

Lab_3- Objective- Experiment with Lists- Stacks- and Queues- Simulate.docx

  • 1. 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 main.cpp #include "List.h" #include <stdlib.h> #include <iostream>
  • 2. using namespace std; template <typename Object> 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<Object> theList; }; template <typename Object> 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)
  • 3. { x = theList.front(); theList.pop_front(); } private: List<Object> theList; }; int main() { int i; const int N = 10; List<int> L1; Stack<int> S1; Queue<int> Q1; List<int>::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 << "List L1 is:" << endl; for (auto it = L1.begin(); it != L1.end(); ++it) { cout << *it << ' '; } // Stack Section example: // // Stack to be created per the above assignment requirment cout << "nStack S1 is:" << endl;; for (i = N - 1; i >= 0; --i) { S1.push(i); cout << S1.top() << " " << endl; }
  • 4. while (!S1.isEmpty()) { cout << S1.top() << endl; S1.pop(i); } // 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