Joel Cochran

Greenhorn
+ Follow
since Sep 28, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Joel Cochran

I'm trying to create 3 different sorting methods (bubble, selection, insertion) that sorts the data in a linked list (custom made). I'm having big time problems with the selection and insertion. I've seen how to do this with arrays, but I just can't seem to make the swap to linked list. I've managed to get the bubble sort to work, but can't seem to get the other two (in fact, I haven't got anything for insertion yet). Here's what I have so far...


Any ideas on what's wrong with the selection sort, and any hints for the insertion? Thanks for all your help!
17 years ago
I need to create a program that creates a Pascal's Triangle based on a given n value, and place it into a 2D Array, and print it to the screen. I've been having a little trouble with my methods. For example, if n = 5 and k = 3, then the output should be like:

1
1 1
1 2 1
1 3 3 1
1 4 6 4 1



PascalArray test = new PascalArray();
test.pascalNonRecursive(5); //GIVES ME 1121331464 as output
System.out.print(test.pascalRecursive(4, 2); //GIVES ME 6 as output

How can I fix (and refine) my code? I obviously need a lot of help, and I will really appreciate anything you give me. Thanks a lot!
17 years ago
Okay! I've changed it a bit more, but for some reason I still have one larger int stuck at the front of the list whenever I print it out.



The output looks like this:
8409
0
0
12
63
97
636
682
773
847
905
933
1258
1338
1826
1992
2543
2868
3026
3221
3287
3671
3796
3800
3829
3945
4420
4607
4782
4950
5242
5337
5898
6091
6154
6160
6216
6598
7089
7154
7203
7515
7542
7654
8147
8149
8511
8687
8907
8984
8997
9976
17 years ago
Yes, I still have questions
How can I make sure that it checks each one? I've added a boolean variable to check whether a swap is made or not, so I've got that covered, but I don't know how to restart or continue from the correct place.
17 years ago
I'm trying to sort a list of integers using bubble sort, insertion sort and selection sort and so far it isn't going so hot. I've created my own LinkedList class (singly linked list) and am a little stuck. Here's everything I have so far...








Ignore the insertionSort method. The bubbleSort methods ALMOST works. For some reason it ignores about half the list and sorts the other half correctly. Any tips/advice on improving my existing code and help on the other sorting methods will be VERY much appreciated. Thanks!!
17 years ago
I'm trying to sort a list of integers using bubble sort, insertion sort and selection sort and so far it isn't going so hot. I've created my own LinkedList class (singly linked list) and am a little stuck. Here's everything I have so far...








Ignore the insertionSort method. The bubbleSort methods ALMOST works. For some reason it ignores about half the list and sorts the other half correctly. Any tips/advice on improving my existing code and help on the other sorting methods will be VERY much appreciated. Thanks!!
17 years ago