-
union in linked list
Hello every one
I face aproblem while i writing this program about append one single linked list to the second one(union) can any one tell me the code that help me to complet the program
code:
public class linked {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i,j; /*,n,value*/;
//Scanner scan = new Scanner(System.in);
SLLNode current;
SLLHeader headerNode = new SLLHeader();
SLLNode firstnode = new SLLNode(3);
SLLNode secondnode = new SLLNode(20);
SLLNode thirdnode = new SLLNode(100);
headerNode.LinktofirstNode = firstnode;
firstnode.next = secondnode;
secondnode.next = thirdnode;
current = HeaderNode.LinktoFirstNode;
i=1;
System.out.println("The values stored in the linked list are:");
while (current != null){
System.out.println("The value at node " +i +" is " +current.data);
current = current.next;
i++;
}
SLLNode B;
SLLHeader BheaderNode = new SLLHeader();
SLLNode Bfirstnode = new SLLNode(1);
SLLNode Bsecondnode = new SLLNode(2);
SLLNode Bthirdnode = new SLLNode(100);
BheaderNode.LinktoFirstNode = Bfirstnode;
Bfirstnode.next = Bsecondnode;
Bsecondnode.next = Bthirdnode;
B = BheaderNode.LinktoFirstNode;
j=1;
System.out.println("The values stored in the second linked list are:");
while (B != null){
System.out.println("The value at node " +j +" is " +B.data);
B = B.next;
j++;
}}}
-
3node.next = 4node;
but do use know the meaning of union?
if union, elements, exist in both set, show appear once after union
-
thank you for your help
but i have two single linked list not one as you understand
I want to connect between two these
i now the step but i can not implement it with code
the steps are
1- traverse the first SLL
2- assign the last node of the first linked list to the first node at the second SLL >>
-
I need more help please>>
-
aehm. well its a programming assignment; but this assignment is unsuitable for java. you dont want implement list structures in java because there are already classes wich provide the nescessary functionality.
but of course it is important to understand how such list work. we aso had to implement list packages in our study but that was in ada95.
to fully understand the problem i suggest you implement list in c, ada, or other more imperative language. of course you can do this with java too, but you have to implement a list in an object oriented manner. it's a bit different.