so algorithm 2.7 is a linked search I posted it below .....NOTE (UNIFORM() is suppose to be a random number selector from 1 to n)
=========================================================
HERE IS WHERE I AM AT
// I used the list array for loop to print out the linked list to ck myself
using System;
using System.Collections.Generic;
using System.Text;
namespace TreeSort
{
class program
{
static void Main()
{
int[] _list = { 1, 3, 7, 9, 11 };
int n = 12;
int head = 0;
int next = 2;
int x = 12;
LinkedList list = new LinkedList(_list);
list.AddFirst(head);
LinkedListNode first = list.First;
list.AddAfter(first, next);
list.AddLast(n);
int[] ListArray = new int[list.Count];
list.CopyTo(ListArray, 0);
int geuss = list.Count;
foreach (int y in ListArray)
{
Console.WriteLine(y);
}
for (int i = head; i < n; i++)
{
}
Console.ReadKey();
}
}
}
VulpesPosted Feb 24, 2015, 5:08 PM
I think the best thing to do therefore is to write your own 'bare bones' SinglyLinkedList
I've also simplified the method parameters as n, head and next can all be deduced from the SinglyLinkedList itself and so can therefore be omitted from the parameter list.
Finally, we have the usual problem with these algorithms that .NET collections are zero based rather than 1-based and so adjustments need to be made for that:
The output is:
VulpesPosted Feb 24, 2015, 6:46 PM
Here's essentially the program you started writing on that basis i.e. without using a custom SinglyLinkedList
The output now is:
Although you could code the LinkedListSearch first, it can be difficult when you're translating pseudo-code to visualize exactly how the equivalent C# code is going to look without having something concrete to work from.
So, personally, I prefer to work the other way around by writing the C# class (or extension method) first but being prepared to alter it if I then find it doesn't quite do what's wanted.
Philip HarrisPosted Feb 24, 2015, 5:51 PM
When you look at a problem like this where do you start, I start from the top and go straight down but would it be easier to work backwards and code the LinkedListSearch() first?