Class 12 ISC - Java Linked List Implementation

Class 12th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 12th java topics includes revision of class 11th, constructors, user-defined methods, objects and classes, library classes , etc.
class Node
{
    int data;
    Node next;
    //default constructor to create a new node
    Node(int data)
    {
    this.data=data;
    next=null;
    }
}
class Linkedlist
{
Node start;
//Inserting element at the finish of linkedlist
public void add(int data)
{
    Node new_node=new Node(data);
    
    //check whether first node is created or not
    if (start==null)
        start=new_node;
    // if it's not a first node
    else
    {
        Node n=start;
        //Reaching null reference i.e,finish of linked list
        while(n.next!=null)
        {
            n=n.next;
        }
        //on reaching null reference
        n.next=new_node;
    }
}
// Inserting element at the start of linkedlist
public void addToStart(int data)
{
    Node new_node=new Node(data);
    new_node.next=start;
    start=new_node;   
}
//Inserting element at definite position in linked list
public void insert(int index,int data)
{
    Node new_node=new Node(data);
    
    Node n=start;
    // Reaching at specified position-1
    for(int i=1;i < index-1;i++)
    {
        n=n.next;
    }
    new_node.next=n.next;
    n.next=new_node;
}
// deleting element of the linked list
public void deleteAt(int index)
{
    Node n=start;
    Node n1=null;
    // Reaching at specified position-1
    for(int i=1;i< index-1;i++)
    {
       n=n.next; 
    }
    //Picking the node to be deleted
    Node del=n.next;
    
    n.next=del.next;
    del=null;
}
public void display()
{
    Node n=start;
    //Reaching null reference i.e,end of linked list
    while(n.next!=null)
    {
        System.out.print(n.data+",");
        n=n.next;
    }
    //print last value with null reference
    System.out.println(n.data);
}
}



Testing Linked List :
class Test
{
    public static void main(String args[])
    {
       Linkedlist list=new Linkedlist();
       list.add(9);
       list.add(12);
       list.add(25);
       list.add(76);
       //add at the beginning
       list.addToStart(23);
       //insert at specified position
       list.insert(2,34);
       //delete at specified position
       list.deleteAt(3);
       //display link_list
       list.display();
    }
}




Program :

A linked list is formed from the objects of the class Node. The class structure of the Node is given below: 
class 
{ 
        Node 
        int n ; 
        Node next; 
} 
Write an Algorithm OR a Method to find the product of the integer numbers from an existing linked list. 
The Method declaration is as follows : 
Void Product_Node (Node str) 
Solution:

void prod(Node str)
{
    Node node=str;
    int p=1;
    while(node!=null)
    {
        p*=node.data;
        node=node.next;
    }
    System.out.println(p);
}



Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com