Ask Data Structure Expert

data structures class this project will give you an introduction. There are two important data structures that you will learn and use. The first is a stack, it is a LIFO (Last In First Out) structure. You can think of it like a a stack of plates in your cabinet. You pile plates on top of each other when you put them away and you take a plate from the top of the pile when you need to use one. This functionality is called push (add to the top of the stack) and pop ( remove from the top of stack). There is one last function that most stacks have. This function is called peek because it will allow you to see what is at the top of the stack without removing it.

The other popular data structure is called a queue. The queue is a FIFO (First In First Out) data structure and you can think of it like standing in line at Disneyland. If you are fortunate enough to be first in line then you are the first person to get on the ride. You will see the stack and the queue all over computers if you study operating systems. The stack is used to store and keep track of variables and the queue is used to store data that is waiting to be processed. This is just to name a couple. In the operating system tasks that are being scheduled to run are put into the queue. There is a slight difference in that many of these queues are called priority queues in that each taks added to the queue is assigned a priority. The higher the priority a task has, the closer it gets to the front of the queue.

Your task is to create a priority queue class calle priQueue that is derived from the vector class. Your class should be constructed as a template class so that the type of data the queue operates on can easily be changed:

priQueue iQueue; // holds ints

priQueue sQueue; // holds string.

Your priority queue should be sorted by priority based on a value from 1 to 10. If a number is assigned that is outside the range of 1 to 10 you should give the element a value of 5. What this means is that each time an element is added to the queue it should be put in order by priority. If multiple elements are given the same priority their position relative to each other is unimportant as long as they are prioritized relative to other elements in the queue.

Your priQueue should have the following functionallity:

  • enqueue - Add an element to the queue
  • dequeue - Remove element from the front of the queue
  • peek - Return value at front of queue do not remove it
  • size - Returns the number of items in the queue.

Specifics

You should create a struct called qElem that will hold both the priority of the element and the data to be put in the queue. The struct should also be of template type so that the value it holds can be of any type. The priority variable type should be an int.

The priQueue class should be derived from vector and should also be a template class so that it can operate on any type. The enque function should be adding a qElem struct so that the data and the prority are coupled. This needs to be done so that the data and priority are related for sorting. Here is an example:

priQueue que;;

que.enqueue("Hello", 3);
que.enqueue("Goodbye", 9); // You are passing a string an an int but you should store a qElem struct.

string s = que.dequeue();

The string s at this point should hold "Goodbye" even though it was put in last because it has a higher priority.

Sorting your queue. You are to create your own sort functionality. Pick any sort that you would like but the bubble sort might be the easiest to implement.

 

 

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M9451909

Have any Question?


Related Questions in Data Structure

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As