Reimplement the bag class from Figure 4.17 so that the items of the bag are stored with

Question:

Reimplement the bag class from Figure 4.17 so that the items of the bag are stored with a new technique. Here’s the idea: Each node of the noefw linked list contains two integers. The first integer is called the count, and the second integer is called the data. As an example, if a node has a count of 6 and data of 10, then this means that the bag has six copies of the number 10.

The nodes of the linked list should be kept in order from the smallest data (at the head of the list) to the largest (at the tail of the list). You should never have two different nodes with the same data, and if the count in a node drops to zero (meaning there are no copies of that node’s data), then the node should be removed from the linked list.

The public member functions of your new class should be identical to those in Figure 4.17.

Figure 4.17

// FILE: IntLinkedBag.java from the package edu.colorado.collections // Documentation is available in Figure 4.12 on page 216 or from the IntLinkedBag link at // http://www.cs.colorado.edu/-main/docs/. package edu.colorado.collections; import edu.colorado.nodes.IntNode; public class IntLinkedBag implements Cloneable { // INVARIANT for the Bag ADT: // 1. The elements in the Bag are stored

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: