The packaging division at Complex Circuits Inc. is assigned the task of packing
ID: 3804933 • Letter: T
Question
The packaging division at Complex Circuits Inc. is assigned the task of packing integrated circuit chips into boxes for shipment. Boxes come in different sizes and the capacity of a box (in terms of number of chips) is an exponent of 2, i.e., boxes can hold 1, 2, 4, 8, 16….chips. Each chip has the following parameters:
weight – a positive, real number in the range of 0-1
id – positive integer in the range of 1000-9999
priority – a positive integer in the range of 1-100
Boxes carrying chips arrive on the production line at the end of each hour in lots. The maximum number of chips that can be produced in each lot is 128. The software developer for the packaging division plans to use a binomial queue to represent the data structure for the chips, boxes and lots - each lot corresponds to a binomial queue, each box corresponds to a binomial tree and each chip corresponds to a node in the binomial tree.
Write a program in Java that does the following:
Input:
input the number of lots
randomly generate a number in the range of 1-128, to denote the number of chips produced in each lot; instantiate the chip object for each chip
for each lot, insert each chip object into a binomial queue, using the priority parameter as the key. Make sure that you satisfy the heap order property while creating the binomial queue. You should randomly generate each chip's parameters within the prescribed range, when you instantiate the chip object
deleteMin(int lot): deletes the chip with the minimum key in the lot (remember to adjust nodes after the delete to restore the binomial queue structure)
levelOrder(int lot): prints the level order traversal of each binomial tree in the binomial queue corresponding to the parameter lot. Nodes within each level should be put inside square brackets while printing; each node's (chip's) parameters should be put inside curly braces. (see sample I/O below)
Finally, you need to write a user interface for the program. Sample input and output are given below:
> Enter the number of lots in this production: 3
Randomly generating number of chips in each lot...
Lot 1: 7
Lot 2: 23
Lot 3: 4
Generating the chips for each lot:
Lot 1, Chip 1: {0.2, 3425, 14}
Lot 1, Chip 2: {0.7, 1298, 7}
Lot 1, Chip 3: {0.9, 1389, 15}
Lot 1, Chip 4: {0.3, 1929, 35}
Lot 1, Chip 5: {0.5, 9526, 92}
Lot 1, Chip 6: {0.1, 1748, 5}
Lot 1, Chip 7: {0.2, 7284, 51}
Lot 2, Chip 1: {0.5, 1357, 45}
Lot 2, Chip 23: {0.7, 3313, 39}
Lot 3, Chip 1: {0.7, 3313, 39}
Lot 3, Chip 4: {0.4, 7163, 27}
> Enter a choice: 1) deleteMin(lot), 2) levelOrder (lot), 3) exit: 2
> Enter the lot number: 1
> Printing level order traversal of lot 1:
Box 1: [{0.2, 7284, 51}]
Box 2: [{0.1, 1748, 5}] [{0.5, 9526, 92}]
Box 3: [{0.7, 1298, 7}] [{0.2, 3425, 14} {0.9, 1389, 15}] [{0.3, 1929, 35}]
> Enter a choice: 1) deleteMin(lot), 2) levelOrder (lot), 3) exit: 1
> Enter the lot number: 1
> Deleted minimum priority chip: {0.1, 1748, 5}
> Enter a choice: 1) deleteMin(lot), 2) levelOrder (lot), 3) exit: 2
> Enter the lot number: 1
> Printing level order traversal of lot 1:
Box 1:
Box 2: [{0.2, 7284, 51}] [{0.5, 9526, 92}]
Box 3: [{0.7, 1298, 7}] [{0.2, 3425, 14} {0.9, 1389, 15}] [{0.3, 1929, 35}]
> Enter a choice: 1) deleteMin(lot), 2) levelOrder (lot), 3) exit: 3
Bye!
Explanation / Answer
Answer:
#include<iostream>
using namespace std;
struct node
{
int info;
node *later;
}*front_end = NULL,*rear_end = NULL,*p = NULL,*node_pointer = NULL;
void push(int value)
{
node_pointer = new node;
node_pointer->info = value;
node_pointer->later = NULL;
if(front_end == NULL)
{
front_end = rear_end = node_pointer;
rear_end->later = NULL;
}
else
{
rear_end->later = node_pointer;
rear_end = node_pointer;
rear_end->later = NULL;
}
}
int remove()
{
int value;
if(front_end == NULL)
{
cout<<" queue is empty ";
}
else
{
p = front_end;
value = p->info;
front_end = front_end->later;
delete(p);
return(value);
}
}
int main()
{
int n,c = 0,value;
cout<<"Enter the number of values to be pushed into queue ";
cin>>n;
while (c < n)
{
cout<<"Enter the value to be entered into queue ";
cin>>value;
push(value);
c++;
}
cout<<" Deleted Values ";
while(true)
{
if (front_end != NULL)
cout<<remove()<<endl;
else
break;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.