Java Program For Set Intersection
Java Program For Set Intersection
*;
class Node
{
public int data;
public Node next;
public Node(int value)
{
data=value;
}
public void displaynode()
{
System.out.print(data+" ");
}
}
class linklist
{
public Node first;
public linklist()
{
first=null;
}
public void createlist(int x)
{
Node newnode=new Node(x);
if(first==null)
first=newnode;
else
{
Node current=first;
while(current.next!=null)
current=current.next;
current.next=newnode;
}
}
Node current=first;
Node newnode=new Node(num);
while(current.data!=key && current!=null)
{
current=current.next;
}
newnode.next=current.next;
current.next=newnode;
}
previous=current;
current=current.next;
}
if(previous==null)
{
first=current.next;
}
else if(current==null)
System.out.println("The element is not present");
else
{
previous.next=current.next;
}
}
list3.createlist(current.data);
current=current.next;
}
return list3;
}*/
}
}
}
System.out.println("Enter the number of nodes of list2:");
temp=br.readLine();
int m=Integer.parseInt(temp);
System.out.println("Enter the nodes of list2:");
for(int i=1;i<=m;i++)
{
temp=br.readLine();
list2.createlist(Integer.parseInt(temp));
}
do
{
System.out.println("MENU:");
System.out.println("1:insert 2:delete 3:sorted insert 4:search ");
temp=br.readLine();
ch=Integer.parseInt(temp);
switch(ch)
{
case 1:
System.out.println("position");
temp=br.readLine();
k=Integer.parseInt(temp);
System.out.println("Enter the node");
temp=br.readLine();
m=Integer.parseInt(temp);
list3.insert1(k,m);
list3.display();
break;
case 2:
System.out.println("element");
temp=br.readLine();
list3.delete(Integer.parseInt(temp));
list3.display();
break;
case 3:
System.out.println("position");
temp=br.readLine();
int pos=Integer.parseInt(temp);
System.out.println("Enter the element");
temp=br.readLine();
int num=Integer.parseInt(temp);
list3.insert2(pos,num);
list3.display();
break;
case 4:
System.out.println("element");
temp=br.readLine();
Node n=list3.search(Integer.parseInt(temp));
if(n!=null)
System.out.println("present ");
else
System.out.println("not present");
break;
case 5:
System.out.println("After union");
list3.intersect(list1,list2);
list3.display();
}
}while(ch==1||ch==2||ch==3||ch==4);
}
}