I am using the above for the first time and I am getting quite lost.

We've been given the following line...

public Node less (int n, Node l)

We have to use recursion to write a method which takes as input a linked list and a number and return a list of elements smaller than that number.

Can anyone help, even with the next line?

If only it was like Filter in Haskell.

Any pointers on linked lists, nodes or quicksort would be great.

We've been given the following line...

public Node less (int n, Node l)

We have to use recursion to write a method which takes as input a linked list and a number and return a list of elements smaller than that number.

I really hate homework assignments that does this. When the instructor gives you part of the code, it tends to cause more confusion than actually help.

You need to understand what the line is. The paragraph is asking you for "a method which takes as input a linked list and a number and return a list of elements". So, based on the line given, and the description, what part of it defines a method, and what defines a linked list?

Henry

Originally posted by Charlie Jackpot:

I think "Node l" refers to the linked list.

Okay good. And n is referring to the number to be compared to. With this you can form the method.

Now, did your instructor teach you the algorithm for the quick sort? Can you form the body of the method, from what you were taught?

Henry

Originally posted by Henry Wong:

Okay good. And n is referring to the number to be compared to. With this you can form the method.

Now, did your instructor teach you the algorithm for the quick sort? Can you form the body of the method, from what you were taught?

Henry

Well, he gave us the quicksort method but used it on an Array.

I am not sure how to use it with Linked Lists.

EDIT:

I found this....

public static void Quicksort(int A[], int f, int l)

{

if (f >= l) return;

int pivot_index = partition(A, f, l);

Quicksort(A, f, pivot_index);

Quicksort(A, pivot_index+1, l);

}

[ November 13, 2008: Message edited by: Charlie Jackson ]

Originally posted by Charlie Jackson:

Well, he gave us the quicksort method but used it on an Array.

I am not sure how to use it with Linked Lists.

Well, it is the technique that is important. If you understood how it worked with an array, it is easily translated to a linked list. Just take a shot at it, provide the code here, and we can give you hints in the right direction.

Now... Did your instructor provide you with the implementation for Node? Or are you expected to implement your own linked list too?

Henry

Originally posted by Henry Wong:

Well, it is the technique that is important. If you understood how it worked with an array, it is easily translated to a linked list. Just take a shot at it, provide the code here, and we can give you hints in the right direction.

Now... Did your instructor provide you with the implementation for Node? Or are you expected to implement your own linked list too?

Henry

I don't understand it for Array either

public static void main(String argv[])

{

int A[] = new int[argv.length];

for (int i=0 ; i < argv.length ; i++)

A[i] = Integer.parseInt(argv[i]);

Quicksort(A, 0, argv.length-1);

for (int i=0 ; i < argv.length ; i++)

System.out.print(A[i] + " ");

System.out.println();

}

The Node reference presumably points to the first node in the linked list which has the specified value.

Originally posted by Campbell Ritchie:

There appear to be problems about sorting LinkedLists; the Collections class copies the list into an array.

There aren't problems sorting a LinkedList, the problem is that the algorithm used in Collections.sort() depends on a random access data structure. That's not an issue if a different algorithm is chosen.

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter