Selection Sort algorithm using C#

In selection sort algorithm it takes smallest value from the array and move the value to the left.This process will continue until the complete array is sorted.

Algorithm


namespace SelectionSortAlgorithm
{
internal class Program
{
private static readonly int[] ArrayToBeSorted = new[] {5, 1, 0, 2};
private static void Main(string[] args)
{
int i;
for (i = 0; i < ArrayToBeSorted.Length - 1; i++)
{
int min = i;
int j;
for (j = i + 1; j < ArrayToBeSorted.Length; j++)
{
if (ArrayToBeSorted[j] < ArrayToBeSorted[min])
{
min = j;
}
}
int temp = ArrayToBeSorted[i];
ArrayToBeSorted[i] = ArrayToBeSorted[min];
ArrayToBeSorted[min] = temp;
}
int[] sortedResult = ArrayToBeSorted;
}
}
}

Enjoy coding…

Linked List

Introduction 

In computer science, a linked list is a data structure consisting of a group of nodes which together represent a sequence.

Node

The Node full fills two function. The first function is a mechanism of provide a piece of data to the node.For example integer value 1 0 in the below figure.

images

and the second function is to pointing to the next node.

How to create a Linked List using C#?


public class LinkedList
{

public static void ConstructLinkedList()
{
//Creating a first node and assign the value 1 to the firstnode
var firstNode = new Node {CurrentValue = 1};
var secondNode = new Node {CurrentValue = 2};
//Pointing the FirstNode to the SecondNode
firstNode.NextNode =secondNode;
//Creating the third node and assign a value to 3
var thirdNode = new Node {CurrentValue = 3};
//Pointing the second node to the third node
secondNode.NextNode = thirdNode;
//Display all the Linked List
DisplayLinkedList(firstNode);
}

public static void DisplayLinkedList(Node node)

{
//Looping through all the nodes and print the value in it
while (node!=null)
{
Console.WriteLine(node.CurrentValue);
node = node.NextNode;
}
}
}

// This is a node which contain two properties , One for setting the current node and other is for setting the next node
public class Node
{
public int CurrentValue { get; set; }
public Node NextNode { get; set; }
}

Enjoy coding…..