How do I limit the size of "com" from the combine function? I want it to have a strict size of 4, but it still allows more than 4 in size.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

How do I limit the size of "com" from the combine function? I want it to have a strict size of 4, but it still allows more than 4 in size.

 

import java.util.LinkedList; public class Lab5 { // BEGIN EDITING HERE // CREATE VARIABLES YOU MAY NEED, SUCH AS: // public int count=0; /******************************************** Requirement: Replace this comment here with a comment that explains how your rules work and why you believe it is fair. *********************************************/ private LinkedList<Integer> stack; public void combine() { if(com.size()>4){ return; }// Limit to 4 elements if(pri.size()>0) com.add(pri.pop()); // Something is in priority, so pop it over to combined else if(reg.size()>0) com.add(reg.pop()); // If priority is empty, pop something from regular to combined } // DO NOT EDIT BELOW HERE // The three lists: regular, priority, and combined private LinkedList<Integer> reg, pri, com; // Constructor: Make three empty FIFO queues public Lab5() { reg = new LinkedList<Integer>(); pri = new LinkedList<Integer>(); com = new LinkedList<Integer>(); } // Add an element to the regular queue public void addReg(Integer i) { reg.add(i); combine(); } // Add an element to the priority queue public void addPri(Integer i) { pri.add(i); combine(); } // Pop an element off the combined queue public Integer pop() { Integer i = com.pop(); combine(); return i; } // Show all three queues as a string public String toString() { String s = "REG:"+reg+" "; s+= "PRI:"+pri+" "; s+= "COM:"+com; if(com.size()>4) s+= " WARNING: COMBINED LINE EXCEEDS 4"; return s; } // Create the three queues and push/pop elements on/off it public static void main(String[] args) { Lab5 qs = new Lab5(); qs.addReg(1); System.out.println(qs); qs.addPri(11); System.out.println(qs); qs.addPri(12); System.out.println(qs); qs.addPri(13); System.out.println(qs); qs.addReg(2); qs.pop(); System.out.println(qs); qs.addPri(14); System.out.println(qs); qs.addPri(15); qs.pop(); System.out.println(qs); qs.addPri(16); System.out.println(qs); qs.addReg(3); qs.pop(); System.out.println(qs); qs.addReg(4); System.out.println(qs); qs.addPri(17); System.out.println(qs); qs.addPri(18); System.out.println(qs); qs.addPri(19); System.out.println(qs); qs.addReg(5); qs.pop(); System.out.println(qs); qs.addPri(20); System.out.println(qs); qs.addPri(21); qs.pop(); System.out.println(qs); qs.addPri(22); System.out.println(qs); qs.addReg(6); qs.pop(); System.out.println(qs); qs.pop(); System.out.println(qs); qs.pop(); System.out.println(qs); qs.pop(); System.out.println(qs); qs.pop(); System.out.println(qs); qs.pop(); System.out.println(qs); }

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY