linearnode java

Solutions on MaxInterview for linearnode java by the best coders in the world

showing results for - "linearnode java"
Gianluca
05 Feb 2019
1    //************************************************************
2    //  LinearNode.java       Authors: Lewis/Chase
3    //
4    //  Represents a node in a linked list.
5    //************************************************************
6    
7    package jss2;   
8
9
10    public class LinearNode<E>
11    {
12       private LinearNode<E> next;
13       private E element;
14    
15       //---------------------------------------------------------
16       //  Creates an empty node.
17       //---------------------------------------------------------
18       public LinearNode()
19       {
20          next = null;
21          element = null;
22       }
23    
24       //---------------------------------------------------------
25       //  Creates a node storing the specified element.
26       //---------------------------------------------------------
27       public LinearNode (E elem)
28       {
29          next = null;
30          element = elem;
31       }
32    
33       //---------------------------------------------------------
34       //  Returns the node that follows this one.
35       //---------------------------------------------------------
36       public LinearNode<E> getNext()
37       {
38          return next;
39       }
40    
41       //---------------------------------------------------------
42       //  Sets the node that follows this one.
43       //---------------------------------------------------------
44       public void setNext (LinearNode<E> node)
45       {
46          next = node;
47       }
48    
49       //---------------------------------------------------------
50       //  Returns the element stored in this node.
51       //---------------------------------------------------------
52       public E getElement()
53       {
54          return element;
55       }
56    
57       //---------------------------------------------------------
58       //  Sets the element stored in this node.
59       //---------------------------------------------------------
60       public void setElement (E elem)
61       {
62          element = elem;
63       }
64    }
65
66
Agustina
30 Jan 2020
1package jsjf;
2
3/**
4 * Represents a node in a linked list.
5 * 
6 * @author Java Foundations
7 * @version 4.0
8 */
9public class LinearNode<T>
10{
11    private LinearNode<T> next;
12    private T element;
13 
14    /**
15     * Creates an empty node.
16     */
17    public LinearNode()
18    {
19        next = null;
20        element = null;
21    }
22 
23    /**
24     * Creates a node storing the specified element.
25     * @param elem element to be stored
26     */
27    public LinearNode(T elem)
28    {
29        next = null;
30        element = elem;
31    }
32 
33    /**
34     * Returns the node that follows this one.
35     * @return reference to next node
36     */
37    public LinearNode<T> getNext()
38    {
39        return next;
40    }
41 
42    /**
43     * Sets the node that follows this one.
44     * @param node node to follow this one
45     */
46    public void setNext(LinearNode<T> node)
47    {
48        next = node;
49    }
50 
51    /**
52     * Returns the element stored in this node.
53     * @return element stored at the node
54     */
55    public T getElement()
56    {
57        return element;
58    }
59 
60    /**
61     * Sets the element stored in this node.
62     * @param elem element to be stored at this node
63     */
64    public void setElement(T elem)
65    {
66        element = elem;
67    }
68}
69
queries leading to this page
linearnode javalinearnode java