Read without ads and support Scribd by becoming a Scribd Premium Reader.
 
Building a Linked List in Java
 
Linked List
In the Procedural Paradigm a linked list consisted of:
 –
A pointer to the head of the list
 –
Nodes (in dynamic memory i.e. the heap) containing data andadditional next pointers
 –
Modules that would perform a variety of functions as needed:add (in order), traverse, find, delete, etc.
In the Object Oriented Paradigm a linked list willconsist of a class which contains:
 –
The head pointer (globally scoped in the class)
 –
Methods to perform the function listed above
We will also need a class to hold the nodes. We’ll startwith that...
 
Node
class Node {StudentRecord data; Node next; public Node(StudentRecord data) {setData(data);setNext(null);} // Constructor public void setData(StudentRecord data) {this.data = data; // !!!!!!!!!!!!!!!!!!!!!!!!!!} public void setNext(Node next) { this.next = next; } public StudentRecord getData() { return data; } public Node getNext() { return next; } public String toString() {if(data == null)return "Node: null";elsereturn "Node: " + data.toString();}
Comments omittedfor
clarity!!! 
Search History:
Searching...
Result 00 of 00
00 results for result for
  • p.
  • Notes
    Load more