Part 1: Create the Node class - This class will contain all neccecery information about the node of the bag that you wil
Posted: Fri Jul 08, 2022 6:44 am
/**
*
* @author
* @param <T>
*/
public class MyNodeBag<T> implementsSimpleNodeBag<T> {
/*
* you may want to use this, but it is not required to use thismethod you just
* have to use the nodes not arrays, you are allowed to changethe names if you
* want to
*
*/
int size = 0;
Node<T> head = new Node<T>();
// @SuppressWarnings("hiding")
private class Node<T> {
T data;
Node<T>next;
/*
* create a node class here - remember all a node must haveis:
* 1) information about its data
* 2) what node comes next
*
*/
}
/*
* Here you will implement the methods from the interfaceprovided to you you
* may want to create a main method for testing purposes, or addprint
* statements within your methods Remember to also use the builtin debugger in
* eclipse
*
*/
@Override
public int getCurrentSize() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean add(T t) {
// TODO Auto-generated method stub
return false;
}
@Override
public T remove() {
// TODO Auto-generated method stub
return null;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
@Override
public void concatenateBag(MyNodeBag<T> bag) {
// TODO Auto-generated method stub
}
@Override
public void copyBag(MyNodeBag<T> bag) {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
//Main method for testing
}
}
Part 1: Create the Node class - This class will contain all neccecery information about the node of the bag that you will be creating. This class will be a private nested class within your MyNode Bag class. Remember that nodes typically contain just the data, and a way to reach the next node in the bag Part 2: Create the Bag - Here you will implement the bag using the same interface as lab 2, this includes all the same methods that you implemented last time and will have to use the interface provided to you once again. These methods include - getCurrentSize(), isEmpty(), add(), remove(), and clear(). If you do not use the Node class for your handling of the bag, you will get 0 points for this section. When using nodes, each node will point to the next, and when adding or removing a node, you must figure out how to properly organize the nodes. Part 3: Additional methods - These methods will also be included in the interface provided to you. This will include a concatenate Bag (MyNodeBag) method. This method will combine the bag that the method is being called on with the bag in the parameter, causing the bag that it was called on to be altered. This will result in one bag(the bag being altered) containing its original objects as well as the other bags objects, while the parameter bag is left unaltered. You will also create a copyBag(MyNodeBag) method, wich will copy the parameter bag into the bag that the method is being called on. This will essentially clear the bag that it is being called on, and replace it with the parameter bag, leaving you with two bags containing the same objects as the parameter bag. If you do not use the Node class for your handling of the bag, you will get 0 points for this section.