You are on page 1of 8

NODE:

import java.io.*;

class NODE

public int data;

public NODE link;

NODE()

link=null;

data=0;

FUNCTION:

import java.io.*;

class list

public NODE start=new NODE();

public void add_at_end()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

NODE snode=new NODE();


NODE nnode=new NODE();

System.out.println("new node data");

nnode.data=Integer.parseInt(br.readLine());

snode=start;

while(snode.link!=null)

snode=snode.link;

snode.link=nnode;

System.out.println("work done");

public void read()

NODE snode=new NODE();

NODE nnode=new NODE();

snode=start;

while(snode.link!=null)

snode=snode.link;

System.out.println(snode.data);

System.out.println("work done");

}
public void add_at_btw()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

NODE snode=new NODE();

NODE nnode=new NODE();

int place;

System.out.println("enter the place to be inserted");

place=Integer.parseInt(br.readLine());

System.out.println("enter the value to be inserted");

nnode.data=Integer.parseInt(br.readLine());

int count=0;

snode=start;

while(snode.link!=null)

snode=snode.link;

count++;

if(count==place)

nnode.link=snode.link;

snode.link=nnode;

public void search()throws IOException


{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int value;

int count=0;

NODE snode=new NODE();

System.out.println("enter the value to be searched");

value=Integer.parseInt(br.readLine());

snode=start;

while(snode.link!=null)

snode=snode.link;

count++;

if(snode.data==value)

System.out.println("value is there and the pos is= "+count);

public void place_edit()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


int place;

System.out.println("enter the place to be edited");

place=Integer.parseInt(br.readLine());

int count=0;

NODE snode=new NODE();

snode=start;

while(snode.link!=null)

snode=snode.link;

count++;

if(count==place)

System.out.println("enter the new value");

snode.data=Integer.parseInt(br.readLine());

public void value_edit()throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int value;

NODE snode=new NODE();

System.out.println("enter the value to be edited");

value=Integer.parseInt(br.readLine());
snode=start;

while(snode.link!=null)

snode=snode.link;

if(snode.data==value)

System.out.println("enter the new value");

snode.data=Integer.parseInt(br.readLine());

WORKING:

import java.io.*;

class working

public static void main(String args[])throws IOException

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

list a=new list();

int choice;
System.out.println("enter choice:"+'\t'+"1.add at end"+'\t'+"2.to read"+'\t'+"3.add at between"+'\
t'+"4.search");

choice=Integer.parseInt(br.readLine());

while(choice!=0&&choice<7)

System.out.println("enter choice:"+'\t'+"1.add at end"+'\t'+"2.to read"+'\t'+"3.add at


between"+'\t'+"4.search"+'\t'

+"5.edit by place"+'\t'+"6.edit by value");

choice=Integer.parseInt(br.readLine());

switch(choice)

case 1:

a.add_at_end();

break;

case 2:

a.read();

break;

case 3:

a.add_at_btw();

break;

case 4:

a.search();

break;

case 5:

a.place_edit();

break;
case 6:

a.value_edit();

break;

default:

System.out.println("error");

You might also like