SlideShare a Scribd company logo
1 of 19
In Class Assignmetz/CST280W13a-1.pdf
CST 280 In-Class Practice – Week 13
Manually determine the configuration of the priority queue
(stored as a heap) created
by the following operations. Trace the following logic and
define the output:
enqueue(7);
enqueue(17);
enqueue(2);
enqueue(5);
enqueue(22);
enqueue(19);
enqueue(6);
enqueue(11);
enqueue(13);
write the queue contents
dequeue and write front item
enqueue(15);
enqueue(8);
dequeue and write front item
dequeue and write front item
enqueue(24);
enqueue(14);
write the queue contents
Part 2
Then, verify the output by implementing the algorithm by
rewriting the priority
queue demonstration program discussed in class. Files needed:
testPQueue.cpp pqType.h heap.cpp
Deliverables
• This cover sheet (with your names on it)
• Driver source code and output for verification program
exectution.
In Class Assignmetz/CST280W13b.pdf
CST 280 In-Class Practice – Week 13
Use this page as a worksheet to sketch the progression of the
elements up to the first
split for the QuickSort algorithm. Use the middle array element
as the split value:
15 34 99 42 11 41 66 23 55 93 48
Next, access the file quickSort.cpp from the course web page.
Tailor the program
by entering the array values above in place of the integer values
used for an in-class
demonstration. Be sure to adjust the index range to match the
size of this array.
Remember that the parameters to the QuickSort algorithm are
starting and ending index
values, not the size of the array.
Next, insert code to demonstrate the state of the array after the
first split. This should
verify what you did by hand above. Insert the following code
at various points within
the partition function to “see” the array at various stages of
processing:
for (int i = start; i <= end; i++) // <== ADD
cout << set[i] << ' ';
cout << endl;
Insert the code at these positions:
int partition(int set[], int start, int end)
{
int pivotValue, pivotIndex, mid;
mid = (start + end) / 2;
swap(set[start], set[mid]);
pivotIndex = start;
pivotValue = set[start];
for (int scan = start + 1; scan <= end; scan++)
{
if (set[scan] < pivotValue)
{
pivotIndex++;
swap(set[pivotIndex], set[scan]);
}
}
swap(set[start], set[pivotIndex]);
return pivotIndex;
}
Finally, identify the line that matches what you concluded
above.
Deliverables:
Deliver the following for this assignment:
• This work sheet with a sketch of the array first split
• Program source code with required change
• Program output demonstrating array configuration after first
split
In Class Assignmetz/heap.cppIn Class
Assignmetz/heap.cpp// This file contains the definition and impl
ementations of struct HeapType.
// A swap function for a generic data type
template<classItemType>
voidSwap(ItemType& item1,ItemType& item2 )
{
ItemType temp = item1;
item1 = item2;
item2 = temp;
}
// Assumes ItemType is either a built-in simple type or a class
// with overloaded relational operators.
template<classItemType>
structHeapType
{
voidReheapDown(int root,int bottom);
voidReheapUp(int root,int bottom);
ItemType* elements;// Array to be allocated dynamically
int numElements;
};
// This function performs the REHEAP DOWN action to restore
// a binary tree to a heap after a removal from the root
// Postcondition: Heap property is restored.
template<classItemType>
voidHeapType<ItemType>::ReheapDown(int root,int bottom)
{
int maxChild;
int rightChild;
int leftChild;
leftChild = root *2+1;
rightChild = root *2+2;
if(leftChild <= bottom)
{
if(leftChild == bottom)
maxChild = leftChild;
else
{
if(elements[leftChild]<= elements[rightChild])
maxChild = rightChild;
else
maxChild = leftChild;
}
if(elements[root]< elements[maxChild])
{
Swap(elements[root], elements[maxChild]);
ReheapDown(maxChild, bottom);
}
}
}
// This function performs the REHEAP UP action to restore
// a binary tree to a heap after addition of an item at
// the bottom open position
// Postcondition: Heap property is restored.
template<classItemType>
voidHeapType<ItemType>::ReheapUp(int root,int bottom)
{
int parent;
if(bottom > root)
{
parent =(bottom -1)/2;
if(elements[parent]< elements[bottom])
{
Swap(elements[parent], elements[bottom]);
ReheapUp(root, parent);
}
}
}
In Class Assignmetz/pqType.h
// Definition of class PQType, which represents the Priority
Queue ADT
// An array is used to implement the heap for this data type
#include "heap.cpp"
template<class ItemType>
class PQType
{
public:
PQType(int); // Parameterized class constructor
// to initialize max size of heap array
~PQType(); // Class destructor
void MakeEmpty();
// Function: Initializes the queue to an empty state.
// Post: Queue is empty.
bool IsEmpty() const;
// Function: Determines whether the queue is empty.
// Post: Function value = (queue is empty)
bool IsFull() const;
// Function: Determines whether the queue is full.
// Post: Function value = (queue is full)
void Enqueue(ItemType newItem);
// Function: Adds newItem to the rear of the queue.
// Pre: Queue is not full.
// Post: newItem is in the queue.
ItemType Dequeue();
// Function: Removes element with highest priority from the
queue
// and returns it in item.
// Pre: Queue is not empty.
// Post: Highest priority element has been removed from the
queue.
// item is a copy of the removed element.
void ListQueue();
// Write current queue contents back to front
private:
int numItems;
HeapType<ItemType> items;
int maxItems;
};
// -------------------------------------------------------
// IMPLEMENTATION OF PRIORITY QUEUE CLASS
FUNCTIONS
// -------------------------------------------------------
template<class ItemType>
PQType<ItemType>::PQType(int max)
{
maxItems = max;
items.elements = new ItemType[max];
numItems = 0;
}
template<class ItemType>
void PQType<ItemType>::MakeEmpty()
{
numItems = 0;
}
template<class ItemType>
PQType<ItemType>::~PQType()
{
delete [] items.elements;
}
template<class ItemType>
ItemType PQType<ItemType>::Dequeue()
// Post: element with highest priority has been removed
// from the queue; a copy is returned in item.
{
ItemType item = items.elements[0];
items.elements[0] = items.elements[numItems-1];
numItems--;
items.ReheapDown(0, numItems-1);
return item;
}
template<class ItemType>
void PQType<ItemType>::Enqueue(ItemType newItem)
// Post: newItem is in the queue.
{
numItems++;
items.elements[numItems-1] = newItem;
items.ReheapUp(0, numItems-1);
}
template<class ItemType>
bool PQType<ItemType>::IsFull() const
// Post: Function value = true if the queue is full;
// false, otherwise
{
return numItems == maxItems;
}
template<class ItemType>
bool PQType<ItemType>::IsEmpty() const
// Post: Function value = true if the queue is empty;
// false, otherwise
{
return numItems == 0;
}
// Write current queue contents back to front
template<class ItemType>
void PQType<ItemType>::ListQueue()
{
for (int i=0; i<numItems; i++)
cout << items.elements[i] << ' ';
cout << endl;
}
In Class Assignmetz/quickSort.cppIn Class
Assignmetz/quickSort.cpp// This program demonstrates the Quic
kSort Algorithm
#include<iostream>
usingnamespace std;
// Function prototypes
void quickSort(int[],int,int);
int partition(int[],int,int);
void swap(int&,int&);
int main()
{
intarray[10]={7,3,9,2,0,1,8,4,6,5};
int x;// Counter
for(x =0; x <10; x++)
cout <<array[x]<<" ";
cout << endl;
quickSort(array,0,9);
for(x =0; x <10; x++)
cout <<array[x]<<" ";
cout << endl;
return0;
}
//************************************************
// quickSort uses the quicksort algorithm to *
// sort set, from set[start] through set[end]. *
//************************************************
void quickSort(int set[],int start,int end)
{
int pivotPoint;
if(start < end)
{
// Get the pivot point
pivotPoint = partition(set, start, end);
// Sort the first sub list
quickSort(set, start, pivotPoint -1);
// Sort the second sub list
quickSort(set, pivotPoint +1, end);
}
}
//***************************************************
*******
// partition selects the value in the middle of the *
// array set as the pivot. The list is rearranged so *
// all the values less than the pivot are on its left *
// and all the values greater than pivot are on its right. *
//***************************************************
*******
int partition(int set[],int start,int end)
{
int pivotValue, pivotIndex, mid;
mid =(start + end)/2;
swap(set[start], set[mid]);
pivotIndex = start;
pivotValue = set[start];
for(int scan = start +1; scan <= end; scan++)
{
if(set[scan]< pivotValue)
{
pivotIndex++;
swap(set[pivotIndex], set[scan]);
}
}
swap(set[start], set[pivotIndex]);
return pivotIndex;
}
//**********************************************
// swap simply exchanges the contents of *
// value1 and value2. *
//**********************************************
void swap(int&value1,int&value2)
{
int temp = value1;
value1 = value2;
value2 = temp;
}
In Class Assignmetz/testPQueue.cppIn Class
Assignmetz/testPQueue.cpp// This program drives a testing plan
for a priority queue data type. It simulates
// inserting and deleting integers from the priority queue.
#include<iostream>
usingnamespace std;
#include"pqType.h"
int main()
{
PQType<int> theQueue(50);
int anItem;
theQueue.Enqueue(15);
theQueue.Enqueue(24);
theQueue.Enqueue(65);
theQueue.Enqueue(10);
theQueue.Enqueue(88);
theQueue.ListQueue();
theQueue.Enqueue(11);
theQueue.Enqueue(25);
theQueue.Enqueue(55);
theQueue.Enqueue(77);
theQueue.ListQueue();
anItem = theQueue.Dequeue();
cout << anItem <<" out"<< endl;
theQueue.ListQueue();
anItem = theQueue.Dequeue();
cout << anItem <<" out"<< endl;
theQueue.ListQueue();
anItem = theQueue.Dequeue();
cout << anItem <<" out"<< endl;
theQueue.ListQueue();
return0;
}
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx

More Related Content

Similar to In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answerssheibansari
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingMandeep Singh
 
Below is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfBelow is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfaroraenterprisesmbd
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CSteffen Wenz
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptSandipPradhan23
 

Similar to In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx (20)

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Thread
ThreadThread
Thread
 
Array Cont
Array ContArray Cont
Array Cont
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Lecture05
Lecture05Lecture05
Lecture05
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Standard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented ProgrammingStandard Template Library (STL) in Object Oriented Programming
Standard Template Library (STL) in Object Oriented Programming
 
Below is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdfBelow is the question I need help with. It need to be done in Java. .pdf
Below is the question I need help with. It need to be done in Java. .pdf
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Day 1
Day 1Day 1
Day 1
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 

More from bradburgess22840

Develop a detailed outline for the data collection plan to include .docx
Develop a detailed outline for the data collection plan to include .docxDevelop a detailed outline for the data collection plan to include .docx
Develop a detailed outline for the data collection plan to include .docxbradburgess22840
 
Develop a 3–4 page research paper based on a selected case study rel.docx
Develop a 3–4 page research paper based on a selected case study rel.docxDevelop a 3–4 page research paper based on a selected case study rel.docx
Develop a 3–4 page research paper based on a selected case study rel.docxbradburgess22840
 
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docx
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docxDevelop a 5- to 6-slide PowerPoint presentation for a staff meet.docx
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docxbradburgess22840
 
Develop a 5–10-year strategic plan for achieving specific health.docx
Develop a 5–10-year strategic plan for achieving specific health.docxDevelop a 5–10-year strategic plan for achieving specific health.docx
Develop a 5–10-year strategic plan for achieving specific health.docxbradburgess22840
 
Develop a 2–4-page proposal for a policy that should help to imp.docx
Develop a 2–4-page proposal for a policy that should help to imp.docxDevelop a 2–4-page proposal for a policy that should help to imp.docx
Develop a 2–4-page proposal for a policy that should help to imp.docxbradburgess22840
 
Develop a 10- to 12- slide PowerPoint Presentation designed for .docx
Develop a 10- to 12- slide PowerPoint Presentation designed for .docxDevelop a 10- to 12- slide PowerPoint Presentation designed for .docx
Develop a 10- to 12- slide PowerPoint Presentation designed for .docxbradburgess22840
 
DetailsPlease answer the following questions. 1.  Desc.docx
DetailsPlease answer the following questions. 1.  Desc.docxDetailsPlease answer the following questions. 1.  Desc.docx
DetailsPlease answer the following questions. 1.  Desc.docxbradburgess22840
 
Despite the literature supporting technology use in schools as ben.docx
Despite the literature supporting technology use in schools as ben.docxDespite the literature supporting technology use in schools as ben.docx
Despite the literature supporting technology use in schools as ben.docxbradburgess22840
 
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docx
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docxDetails httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docx
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docxbradburgess22840
 
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docx
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docxDescriptionCh .17Newborn transitioningCh. 18Nursing manag.docx
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docxbradburgess22840
 
Description of the assignment The following 4 men created a p.docx
Description of the assignment The following 4 men created a p.docxDescription of the assignment The following 4 men created a p.docx
Description of the assignment The following 4 men created a p.docxbradburgess22840
 
Description of the AssignmentThis assignment presents a mo.docx
Description of the AssignmentThis assignment presents a mo.docxDescription of the AssignmentThis assignment presents a mo.docx
Description of the AssignmentThis assignment presents a mo.docxbradburgess22840
 
Description of theNationalMilitary Strategy2018.docx
Description of theNationalMilitary Strategy2018.docxDescription of theNationalMilitary Strategy2018.docx
Description of theNationalMilitary Strategy2018.docxbradburgess22840
 
Description This is a 4 page paper about either a creative genius o.docx
Description This is a 4 page paper about either a creative genius o.docxDescription This is a 4 page paper about either a creative genius o.docx
Description This is a 4 page paper about either a creative genius o.docxbradburgess22840
 
Describe your experience with electronic healthmedical record.docx
Describe your experience with electronic healthmedical record.docxDescribe your experience with electronic healthmedical record.docx
Describe your experience with electronic healthmedical record.docxbradburgess22840
 
Description Develop a paper describing how the knowledge, skill.docx
Description Develop a paper describing how the knowledge, skill.docxDescription Develop a paper describing how the knowledge, skill.docx
Description Develop a paper describing how the knowledge, skill.docxbradburgess22840
 
Describing Research FindingsResearchers take many steps to p.docx
Describing Research FindingsResearchers take many steps to p.docxDescribing Research FindingsResearchers take many steps to p.docx
Describing Research FindingsResearchers take many steps to p.docxbradburgess22840
 
Description I. Introduction A. Summarize the client. What is the rat.docx
Description I. Introduction A. Summarize the client. What is the rat.docxDescription I. Introduction A. Summarize the client. What is the rat.docx
Description I. Introduction A. Summarize the client. What is the rat.docxbradburgess22840
 
Describing DataNumerical MeasuresChapter 3McGraw-.docx
Describing DataNumerical MeasuresChapter 3McGraw-.docxDescribing DataNumerical MeasuresChapter 3McGraw-.docx
Describing DataNumerical MeasuresChapter 3McGraw-.docxbradburgess22840
 
Describes the use of Computers in Nursing in general clearly and com.docx
Describes the use of Computers in Nursing in general clearly and com.docxDescribes the use of Computers in Nursing in general clearly and com.docx
Describes the use of Computers in Nursing in general clearly and com.docxbradburgess22840
 

More from bradburgess22840 (20)

Develop a detailed outline for the data collection plan to include .docx
Develop a detailed outline for the data collection plan to include .docxDevelop a detailed outline for the data collection plan to include .docx
Develop a detailed outline for the data collection plan to include .docx
 
Develop a 3–4 page research paper based on a selected case study rel.docx
Develop a 3–4 page research paper based on a selected case study rel.docxDevelop a 3–4 page research paper based on a selected case study rel.docx
Develop a 3–4 page research paper based on a selected case study rel.docx
 
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docx
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docxDevelop a 5- to 6-slide PowerPoint presentation for a staff meet.docx
Develop a 5- to 6-slide PowerPoint presentation for a staff meet.docx
 
Develop a 5–10-year strategic plan for achieving specific health.docx
Develop a 5–10-year strategic plan for achieving specific health.docxDevelop a 5–10-year strategic plan for achieving specific health.docx
Develop a 5–10-year strategic plan for achieving specific health.docx
 
Develop a 2–4-page proposal for a policy that should help to imp.docx
Develop a 2–4-page proposal for a policy that should help to imp.docxDevelop a 2–4-page proposal for a policy that should help to imp.docx
Develop a 2–4-page proposal for a policy that should help to imp.docx
 
Develop a 10- to 12- slide PowerPoint Presentation designed for .docx
Develop a 10- to 12- slide PowerPoint Presentation designed for .docxDevelop a 10- to 12- slide PowerPoint Presentation designed for .docx
Develop a 10- to 12- slide PowerPoint Presentation designed for .docx
 
DetailsPlease answer the following questions. 1.  Desc.docx
DetailsPlease answer the following questions. 1.  Desc.docxDetailsPlease answer the following questions. 1.  Desc.docx
DetailsPlease answer the following questions. 1.  Desc.docx
 
Despite the literature supporting technology use in schools as ben.docx
Despite the literature supporting technology use in schools as ben.docxDespite the literature supporting technology use in schools as ben.docx
Despite the literature supporting technology use in schools as ben.docx
 
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docx
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docxDetails httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docx
Details httpsource.sakaiproject.orgviewsvnview=rev&rev=39.docx
 
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docx
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docxDescriptionCh .17Newborn transitioningCh. 18Nursing manag.docx
DescriptionCh .17Newborn transitioningCh. 18Nursing manag.docx
 
Description of the assignment The following 4 men created a p.docx
Description of the assignment The following 4 men created a p.docxDescription of the assignment The following 4 men created a p.docx
Description of the assignment The following 4 men created a p.docx
 
Description of the AssignmentThis assignment presents a mo.docx
Description of the AssignmentThis assignment presents a mo.docxDescription of the AssignmentThis assignment presents a mo.docx
Description of the AssignmentThis assignment presents a mo.docx
 
Description of theNationalMilitary Strategy2018.docx
Description of theNationalMilitary Strategy2018.docxDescription of theNationalMilitary Strategy2018.docx
Description of theNationalMilitary Strategy2018.docx
 
Description This is a 4 page paper about either a creative genius o.docx
Description This is a 4 page paper about either a creative genius o.docxDescription This is a 4 page paper about either a creative genius o.docx
Description This is a 4 page paper about either a creative genius o.docx
 
Describe your experience with electronic healthmedical record.docx
Describe your experience with electronic healthmedical record.docxDescribe your experience with electronic healthmedical record.docx
Describe your experience with electronic healthmedical record.docx
 
Description Develop a paper describing how the knowledge, skill.docx
Description Develop a paper describing how the knowledge, skill.docxDescription Develop a paper describing how the knowledge, skill.docx
Description Develop a paper describing how the knowledge, skill.docx
 
Describing Research FindingsResearchers take many steps to p.docx
Describing Research FindingsResearchers take many steps to p.docxDescribing Research FindingsResearchers take many steps to p.docx
Describing Research FindingsResearchers take many steps to p.docx
 
Description I. Introduction A. Summarize the client. What is the rat.docx
Description I. Introduction A. Summarize the client. What is the rat.docxDescription I. Introduction A. Summarize the client. What is the rat.docx
Description I. Introduction A. Summarize the client. What is the rat.docx
 
Describing DataNumerical MeasuresChapter 3McGraw-.docx
Describing DataNumerical MeasuresChapter 3McGraw-.docxDescribing DataNumerical MeasuresChapter 3McGraw-.docx
Describing DataNumerical MeasuresChapter 3McGraw-.docx
 
Describes the use of Computers in Nursing in general clearly and com.docx
Describes the use of Computers in Nursing in general clearly and com.docxDescribes the use of Computers in Nursing in general clearly and com.docx
Describes the use of Computers in Nursing in general clearly and com.docx
 

Recently uploaded

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx

  • 1. In Class Assignmetz/CST280W13a-1.pdf CST 280 In-Class Practice – Week 13 Manually determine the configuration of the priority queue (stored as a heap) created by the following operations. Trace the following logic and define the output: enqueue(7); enqueue(17); enqueue(2); enqueue(5); enqueue(22); enqueue(19); enqueue(6); enqueue(11); enqueue(13); write the queue contents dequeue and write front item enqueue(15); enqueue(8); dequeue and write front item
  • 2. dequeue and write front item enqueue(24); enqueue(14); write the queue contents
  • 3. Part 2 Then, verify the output by implementing the algorithm by rewriting the priority queue demonstration program discussed in class. Files needed: testPQueue.cpp pqType.h heap.cpp Deliverables • This cover sheet (with your names on it) • Driver source code and output for verification program exectution. In Class Assignmetz/CST280W13b.pdf CST 280 In-Class Practice – Week 13 Use this page as a worksheet to sketch the progression of the elements up to the first split for the QuickSort algorithm. Use the middle array element as the split value:
  • 4. 15 34 99 42 11 41 66 23 55 93 48 Next, access the file quickSort.cpp from the course web page. Tailor the program by entering the array values above in place of the integer values used for an in-class demonstration. Be sure to adjust the index range to match the size of this array. Remember that the parameters to the QuickSort algorithm are starting and ending index values, not the size of the array. Next, insert code to demonstrate the state of the array after the first split. This should verify what you did by hand above. Insert the following code at various points within the partition function to “see” the array at various stages of processing: for (int i = start; i <= end; i++) // <== ADD cout << set[i] << ' '; cout << endl;
  • 5. Insert the code at these positions: int partition(int set[], int start, int end) { int pivotValue, pivotIndex, mid; mid = (start + end) / 2; swap(set[start], set[mid]); pivotIndex = start; pivotValue = set[start]; for (int scan = start + 1; scan <= end; scan++) { if (set[scan] < pivotValue) { pivotIndex++; swap(set[pivotIndex], set[scan]); } } swap(set[start], set[pivotIndex]); return pivotIndex; } Finally, identify the line that matches what you concluded
  • 6. above. Deliverables: Deliver the following for this assignment: • This work sheet with a sketch of the array first split • Program source code with required change • Program output demonstrating array configuration after first split In Class Assignmetz/heap.cppIn Class Assignmetz/heap.cpp// This file contains the definition and impl ementations of struct HeapType. // A swap function for a generic data type template<classItemType> voidSwap(ItemType& item1,ItemType& item2 ) { ItemType temp = item1; item1 = item2; item2 = temp; } // Assumes ItemType is either a built-in simple type or a class // with overloaded relational operators. template<classItemType> structHeapType
  • 7. { voidReheapDown(int root,int bottom); voidReheapUp(int root,int bottom); ItemType* elements;// Array to be allocated dynamically int numElements; }; // This function performs the REHEAP DOWN action to restore // a binary tree to a heap after a removal from the root // Postcondition: Heap property is restored. template<classItemType> voidHeapType<ItemType>::ReheapDown(int root,int bottom) { int maxChild; int rightChild; int leftChild; leftChild = root *2+1; rightChild = root *2+2; if(leftChild <= bottom) { if(leftChild == bottom) maxChild = leftChild; else { if(elements[leftChild]<= elements[rightChild]) maxChild = rightChild; else maxChild = leftChild; } if(elements[root]< elements[maxChild]) { Swap(elements[root], elements[maxChild]); ReheapDown(maxChild, bottom); } } }
  • 8. // This function performs the REHEAP UP action to restore // a binary tree to a heap after addition of an item at // the bottom open position // Postcondition: Heap property is restored. template<classItemType> voidHeapType<ItemType>::ReheapUp(int root,int bottom) { int parent; if(bottom > root) { parent =(bottom -1)/2; if(elements[parent]< elements[bottom]) { Swap(elements[parent], elements[bottom]); ReheapUp(root, parent); } } } In Class Assignmetz/pqType.h // Definition of class PQType, which represents the Priority Queue ADT // An array is used to implement the heap for this data type #include "heap.cpp" template<class ItemType> class PQType
  • 9. { public: PQType(int); // Parameterized class constructor // to initialize max size of heap array ~PQType(); // Class destructor void MakeEmpty(); // Function: Initializes the queue to an empty state. // Post: Queue is empty. bool IsEmpty() const; // Function: Determines whether the queue is empty. // Post: Function value = (queue is empty) bool IsFull() const; // Function: Determines whether the queue is full. // Post: Function value = (queue is full)
  • 10. void Enqueue(ItemType newItem); // Function: Adds newItem to the rear of the queue. // Pre: Queue is not full. // Post: newItem is in the queue. ItemType Dequeue(); // Function: Removes element with highest priority from the queue // and returns it in item. // Pre: Queue is not empty. // Post: Highest priority element has been removed from the queue. // item is a copy of the removed element. void ListQueue(); // Write current queue contents back to front private: int numItems;
  • 11. HeapType<ItemType> items; int maxItems; }; // ------------------------------------------------------- // IMPLEMENTATION OF PRIORITY QUEUE CLASS FUNCTIONS // ------------------------------------------------------- template<class ItemType> PQType<ItemType>::PQType(int max) { maxItems = max; items.elements = new ItemType[max]; numItems = 0; } template<class ItemType>
  • 12. void PQType<ItemType>::MakeEmpty() { numItems = 0; } template<class ItemType> PQType<ItemType>::~PQType() { delete [] items.elements; } template<class ItemType> ItemType PQType<ItemType>::Dequeue() // Post: element with highest priority has been removed // from the queue; a copy is returned in item. { ItemType item = items.elements[0]; items.elements[0] = items.elements[numItems-1];
  • 13. numItems--; items.ReheapDown(0, numItems-1); return item; } template<class ItemType> void PQType<ItemType>::Enqueue(ItemType newItem) // Post: newItem is in the queue. { numItems++; items.elements[numItems-1] = newItem; items.ReheapUp(0, numItems-1); } template<class ItemType> bool PQType<ItemType>::IsFull() const // Post: Function value = true if the queue is full;
  • 14. // false, otherwise { return numItems == maxItems; } template<class ItemType> bool PQType<ItemType>::IsEmpty() const // Post: Function value = true if the queue is empty; // false, otherwise { return numItems == 0; } // Write current queue contents back to front template<class ItemType> void PQType<ItemType>::ListQueue() {
  • 15. for (int i=0; i<numItems; i++) cout << items.elements[i] << ' '; cout << endl; } In Class Assignmetz/quickSort.cppIn Class Assignmetz/quickSort.cpp// This program demonstrates the Quic kSort Algorithm #include<iostream> usingnamespace std; // Function prototypes void quickSort(int[],int,int); int partition(int[],int,int); void swap(int&,int&); int main() { intarray[10]={7,3,9,2,0,1,8,4,6,5}; int x;// Counter for(x =0; x <10; x++) cout <<array[x]<<" "; cout << endl; quickSort(array,0,9); for(x =0; x <10; x++) cout <<array[x]<<" "; cout << endl; return0; }
  • 16. //************************************************ // quickSort uses the quicksort algorithm to * // sort set, from set[start] through set[end]. * //************************************************ void quickSort(int set[],int start,int end) { int pivotPoint; if(start < end) { // Get the pivot point pivotPoint = partition(set, start, end); // Sort the first sub list quickSort(set, start, pivotPoint -1); // Sort the second sub list quickSort(set, pivotPoint +1, end); } } //*************************************************** ******* // partition selects the value in the middle of the * // array set as the pivot. The list is rearranged so * // all the values less than the pivot are on its left * // and all the values greater than pivot are on its right. * //*************************************************** ******* int partition(int set[],int start,int end) { int pivotValue, pivotIndex, mid; mid =(start + end)/2; swap(set[start], set[mid]);
  • 17. pivotIndex = start; pivotValue = set[start]; for(int scan = start +1; scan <= end; scan++) { if(set[scan]< pivotValue) { pivotIndex++; swap(set[pivotIndex], set[scan]); } } swap(set[start], set[pivotIndex]); return pivotIndex; } //********************************************** // swap simply exchanges the contents of * // value1 and value2. * //********************************************** void swap(int&value1,int&value2) { int temp = value1; value1 = value2; value2 = temp; } In Class Assignmetz/testPQueue.cppIn Class Assignmetz/testPQueue.cpp// This program drives a testing plan for a priority queue data type. It simulates // inserting and deleting integers from the priority queue. #include<iostream> usingnamespace std;
  • 18. #include"pqType.h" int main() { PQType<int> theQueue(50); int anItem; theQueue.Enqueue(15); theQueue.Enqueue(24); theQueue.Enqueue(65); theQueue.Enqueue(10); theQueue.Enqueue(88); theQueue.ListQueue(); theQueue.Enqueue(11); theQueue.Enqueue(25); theQueue.Enqueue(55); theQueue.Enqueue(77); theQueue.ListQueue(); anItem = theQueue.Dequeue(); cout << anItem <<" out"<< endl; theQueue.ListQueue(); anItem = theQueue.Dequeue(); cout << anItem <<" out"<< endl; theQueue.ListQueue(); anItem = theQueue.Dequeue(); cout << anItem <<" out"<< endl; theQueue.ListQueue(); return0; }