How to implement Linked list Concept

Posted by Guna27 under C# on 5/2/2013 | Points: 10 | Views : 950 | Status : [Member] | Replies : 1
how to write this code in the form of Linked list with pointer concept

class Sequence
{
public ArrayList Nodes;
public Sequence Next;
}
class Program
{
static void Main(string[] args)
{
Sequence First, Current, Prev;
int[] a = { 1, 3, 4, 5, 8, 11, 13, 14, 15, 18, 20, 21,22,23,24 };
int diff = 1;
First = Current = Prev = null;
for (int i = 0; i < a.Length; i++)
{
Current = new Sequence();
if (First == null)
{
First = Current;
}
if (Prev != null)
Prev.Next = Current;
Prev = Current;
Current.Next = null;
Current.Nodes = new ArrayList();
for (int j = i+1 ; j < a.Length;j++ )
{
Current.Nodes.Add(a[j-1]);
if (a[j] - a[i] == diff)
diff++;
else
{
diff = 1;
i = j-1;
Current = null;
break;
}
if (j == a.Length - 1)
{
Current.Nodes.Add(a[j]);
i = j - 1;
}
}
}
}
}


Guna..............


Responses

Posted by: Guna27 on: 5/2/2013 [Member] Starter | Points: 25

Up
0
Down
Code to display

while (First != null)

{
foreach (var x in First.Nodes)
Console.Write(x + " ");
First = First.Next;
Console.WriteLine();
}


Guna..............

Guna27, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response