Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help writing a few methods in the Generic Node class....and if you could tell me if you see any issues with the methods I

Need help writing a few methods in the Generic Node class....and if you could tell me if you see any issues with the methods I have already written, it would be appreciated

*addNodeAfter() instead of being void, returns the link it creates....just want to make sure my method header is correct and the return type (Node) is correct, or if i need Node

*removeNodeAfter() returns the link it creates (that is the node after the removed element....just want to make sure my method header is correct and the return type (Node) is correct

* toString() creates and returns a string message which reveals the stored value(data) but not the link (non-recursive method documented below is the class, constructor, and a few methods i have written so far...this is part of a much larger project so if anything is unclear as far as specifications, I can provide it

CODE----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

public class Node { // Invariant of the Node class: // 1. Each node has one reference to an E Object, stored in the instance // variable data. // 2. For the final node of a list, the link part is null. // Otherwise, the link part is a reference to the // next node of the list. private E data; private Node link;

/** * Initialize a node with a specified initial data and link to the next * node. Note that the initialLink may be the null reference, * which indicates that the new node has nothing after it. * @param initialData * the initial data of this new node * @param initialLink * a reference to the node after this new node--this reference may be null * to indicate that there is no node after this new node. * @postcondition * This node contains the specified data and link to the next node. **/ public Node(E initialData, Node initialLink) { data = initialData; link = initialLink; }

public Node addNodeAfter(E element) { return link = new Node(element, link); }

public Node addNodeAfter(E element) { return link = new Node(element, link); }

Any help is greatly apprecitated.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions