## Archive for March, 2013

Input : Number of Rows

Output:

1
1 2 1
1 2 3 2 1

Code

```        public static void PrintNumberPattern3(int rows)
{
int i, j, k, l;
//Loop for number of Rows
for (i = 1; i <= rows; i++)
{
//Loop for printing space between numbers
for (l = 0; l < rows - i; l++)
{
Console.Write("  ");
}
// Loop for printing numbers in increasing order
for (j = 1; j < 2 * i + 1; j++)
{
Console.Write(j + " ");
if (j >= i)
{
break;
}
}
// Loop for printing numbers in decreasing order
for (k = j - 1; k > 0; k--)
{
Console.Write(k + " ");
}
Console.WriteLine("");
}
}```

A doubly-linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains two fields, called links, that are references to the previous and to the next node in the sequence of nodes. The beginning and ending nodes’ previous and next links, respectively, point to some kind of terminator, typically a sentinel node or null, to facilitate traversal of the list. If there is only one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items, but in opposite sequential orders. Code

```    public class DoubleLinkList<T>
{
private DoubleNode<T> tail;

{

{
item.Next = item.Previous = null;
tail = item;
return 0;
}

return 0;
}

public int InsertAtTail(DoubleNode<T> item)
{
{
item.Next = item.Previous = null;
tail = item;
return 0;
}

tail.Next = item;
item.Previous = tail;
tail = item;
return 0;
}

{
while (temp != null)
{
Console.Write(temp.Data + "->");
temp = temp.Next;
}
Console.WriteLine(Environment.NewLine);
}

{
var temp = root;
while (temp != null)
{
Console.Write(temp.Data + "->");
temp = temp.Next;
}
Console.WriteLine(Environment.NewLine);
}

public void ShowFromTail()
{
var temp = tail;
while (temp != null)
{
Console.Write(temp.Data + "->");
temp = temp.Previous;
}
Console.WriteLine(Environment.NewLine);
}
}

public class DoubleNode<T>
{
public DoubleNode<T> Next { get; set; }
public DoubleNode<T> Previous { get; set; }
public T Data { get; set; }

}```

Finding largest or smallest element is easy as compare to finding the second largest element in an unsorted array. This problem can be solved using Sorting. Instead of sorting we will use a different approach for solving this problem.

```        public static int FindSecondNdLarge(int[] array)
{
int size = array.Length;
int[] max = new int[] { 0, 0 };
int counter;

if (array > array)
{
max = array;
max = array;
}
else
{
max = array;
max = array;
}

for (counter = 2; counter < size; counter++)
{
if (array[counter] > max)
{
if (array[counter] > max)
{
max = max;
max = array[counter];
}
else
{
max = array[counter];
}
}
}

return max;
}```
` `