In a link list how do I insert at the end of the list using a
"tail" node and without using a tail node.
This is my code I just need an insert method at the end of the
list
public class LinkList_A {
Node head; //---->Creating a variable that
is head which is a reference
int lenght;
public class Node{ ////---->Creating the node
class
int data ; //creating a
variable
Node next; //Creating
anaother variable, Node is just link to the next node,
Node(int d) // a node is just
what ever data we give it
{
data =
d; //the data becomes becomes what ever "d" value is
next =
null; //.next is null at the begining because there is nothing
pointing at it
//because the list is empty
}
}
public void push (int
new_Data) { //---->Puts in a new node
before the head of the list
lenght++;
//so push
becomes the new head
Node new_node = new
Node(new_Data); //---->Create a new value node
new_node.next = head;
//---->That new Node becomes head of the node becuse is the the
one we are
head = new_node;
} //are
putting in regardless if the list is empty or not
In a link list how do I insert at the end of the list using a "tail" node and without using a tail node. This is my code
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
In a link list how do I insert at the end of the list using a "tail" node and without using a tail node. This is my code
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!