| | |
Recursion In C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 1
Reputation:
Solved Threads: 0
The RemoveMin class should remove the first occurrence of the smallest element from the input list. Despite what the inputs are I keep getting the same NullReference error from having 'rem = null'. I don't know if I'm using recursion right or not. I have a feeling the starting reference for the ConsList may not be right. This was a homework assignment but it was due a couple days ago. I just want to understand for future references what I need to do. Anything pointers or examples would be appreciated. Here is the line of code giving me problems.
Here is the class that implements RemoveMin. 'rem' keeps causing a null reference. This class shouldn't need any editing.
C# Syntax (Toggle Plain Text)
public static ConsList<int> RemoveMin(ConsList<int> list, out int min) { ConsList<int> r; min = list.Head; if (list.Tail.Head > min) { r = new ConsList<int>(list.Head, RemoveMin(list.Tail, out min)); return r; } else { r = new ConsList<int>(min, RemoveMin(list.Tail, out min)); return r; } }
Here is the class that implements RemoveMin. 'rem' keeps causing a null reference. This class shouldn't need any editing.
C# Syntax (Toggle Plain Text)
private ConsList<int> SelectionSort(ConsList<int> list) { if (list == null) { return list; } else { int min; ConsList<int> rem = RemoveMin(list, out min); return new ConsList<int>(min, SelectionSort(rem)); } }
Care to post the full code unit so I can load it up in a debugger and test without putting it back together?
![]() |
Similar Threads
- Recursion: when do you use it? (C++)
- C++ Beginner - #include recursion problem (C++)
- Recursion (C++)
- number formatting using recursion (Java)
- Need help with recursion and arrays (C++)
- powers of two, recursion. (C)
- Create menu from properties file by recursion (Java)
- Recursion (C)
Other Threads in the C# Forum
- Previous Thread: vst plugins
- Next Thread: dynamically create datagrid with prepopulated text boxes from datatable
| Thread Tools | Search this Thread |
.net access activedirectory ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox client color combobox connect control conversion csharp custom database datagrid datagridview dataset datetime degrees development disabled displayingopenforms draganddrop drawing encryption enum event excel file foreach form format forms ftp function gdi+ httpwebrequest image index index-error input install java label list listbox listener mandelbrot math mathematics mouseclick mysql operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox serialization server setup sleep socket sql statistics stream string table tcp text textbox thread time timer update user usercontrol validation visualstudio webbrowser windows winforms wpf xml






