Results 1 to 9 of 9
Thread: C# Sorting
- 01-26-2011, 10:55 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 11
- Rep Power
- 0
C# Sorting
I know this really should only be about Java but I have a small issue involving the sorting of linked lists. C# is quite similar to Java(as i understand) and I was wondering how one could go about sorting a linked list. I've created a blank list(to copy to), and started an algorithm, how can <T> list be sorted??
private LinkGen<T> list;
public void Sort()
{
LinkListGen<T> newList = new LinkListGen<T>();//new blank list
while (list != null)
{
if (list == null)
{
newList.AppendItem(list.HeadList);
}
else
{
}
list = newList.list;
}
- 01-26-2011, 11:09 PM #2
By using a static method in the Collections class. How that translates to C# is probably your homework assignment.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-27-2011, 12:11 AM #3
- 01-27-2011, 07:08 AM #4
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Well, arrays have indexes, so you just swap the elements by index when sorting. How does a linked list work? Each element is represented by its value and a pointer to the next element (if it's a singly linked list). So how would you swap the two elements?
Ever seen a dog chase its tail? Now that's an infinite loop.
- 01-27-2011, 07:38 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,589
- Blog Entries
- 7
- Rep Power
- 17
- 01-27-2011, 08:25 AM #6
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Hey Jos, I was asking the OP how he would tackle the problem instead of just posting code. Just clarifying :)
Ever seen a dog chase its tail? Now that's an infinite loop.
- 01-27-2011, 08:27 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,589
- Blog Entries
- 7
- Rep Power
- 17
- 01-27-2011, 08:30 AM #8
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Nah, I should probably have quoted the OP to clarify I was talking to him. Please don't keep your mouth shut as want more stuff like the scizophrenia recursion examples from you :D
Ever seen a dog chase its tail? Now that's an infinite loop.
- 01-27-2011, 09:51 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,589
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Sorting
By Freakzoyd in forum New To JavaReplies: 3Last Post: 01-21-2011, 02:02 AM -
little help with sorting
By drgnfire25 in forum New To JavaReplies: 3Last Post: 01-15-2011, 09:23 PM -
Help in sorting
By nn12 in forum New To JavaReplies: 3Last Post: 01-08-2011, 06:15 PM -
sorting
By jot321 in forum New To JavaReplies: 18Last Post: 10-02-2008, 10:30 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks