pot tom

Greenhorn
+ Follow
since Apr 27, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by pot tom

I have modified the code, can anyone please help me.
16 years ago
Sorry for posting here, badly I need help from expert like you!

Can any one explain why my codes does works properly, I mean result what I am suppose to get, it not getting through this method. This is just two method. from my class "MainClass.java".



That was the difference method which will take two list head1, head2

lets say: head1 lis: 3 ; 6 ; 9 ; 10
head2 list is: 5; 6; 10

Answer should be: 3->9, can any one correct me!

Here is another method:



lets say: head1 lis: 3 -> 6 -> 9 -> 10
head2 list is: 5-> 6-> 10

Answer should be: 3,5,6,9,10, can any one correct me!




Note that IntNode class contain:



This is how I was trying to test:



seems like program output partly not what I am expecting result.
[ April 27, 2007: Message edited by: pot tom ]
16 years ago
Sorry for posting here, badly I need help from expert like you!

Can any one explain why my codes does not runs?

public static IntNode difference(IntNode head1, IntNode head2)
{
if(head1==null && head2==null) return null;
if(head1==null) return null;
if(head2==null) return head1;

if(head1.data==head2.data){
IntNode special = difference(head1.next, head2.next);
return special;
}
if(head1.data!=head2.data){
IntNode special = difference(head1.next, head2);
head1.next=special;

}

if (head1.data < head2.data){
IntNode special =difference(head1, head2.next);
return special;
}

return head1;

}

lets say: head1 lis: 3 -> 6 -> 9 -> 10
head2 list is: 5-> 6-> 10

Answer should be: 3->9, can any one correct me!


public static IntNode mergeUnique(IntNode head1, IntNode head2)
{


if(head1==null && head2==null) return null;
if(head1==null) return head2;
if(head2==null) return head1;


if(head1.data==head2.data){
IntNode special = difference(head1.next, head2.next);
return special;
}
if(head1.data!=head2.data){
IntNode special = difference(head1.next, head2);
head1.next=special;

}


if (head1.data < head2.data){
IntNode special=mergeUnique(head1.next, head2);
head1.next=special;
return head1;
}

if (head2.data < head1.data){
IntNode special=mergeUnique(head1, head2.next);
head2.next=special;
return head2;
}




return head1;

}

lets say: head1 lis: 3 -> 6 -> 9 -> 10
head2 list is: 5-> 6-> 10

Answer should be: 3,5,6,9,10, can any one correct me!




Note that IntNode class contain:

public class IntNode
{
public int data;
public IntNode next;

public IntNode()
{
data = 0;
next = null;
}

public IntNode(int data)
{
this.data = data;
next = null;
}

public IntNode(int data, IntNode next)
{
this.data = data;
this.next = next;
}
}
16 years ago