-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
99 lines (94 loc) · 3.15 KB
/
Copy pathProgram.cs
File metadata and controls
99 lines (94 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Globalization;
namespace algoExersice
{
internal class Algo
{
static void Main(string[] args)
{
/* Dijkstra run*/
/*
WeightedGraph graph = new WeightedGraph(50);
graph.InsertVertex("0");
graph.InsertVertex("1");
graph.InsertVertex("2");
graph.InsertVertex("3");
graph.InsertVertex("4");
graph.InsertVertex("5");
graph.InsertVertex("6");
graph.InsertVertex("7");
graph.InsertVertex("8");
graph.InsertEdge("0", "1", 5);
graph.InsertEdge("0", "3", 2);
graph.InsertEdge("0", "4", 8);
graph.InsertEdge("1", "2", 3);
graph.InsertEdge("1", "4", 2);
graph.InsertEdge("1", "5", 6);
graph.InsertEdge("2", "5", 4);
graph.InsertEdge("3", "4", 7);
graph.InsertEdge("3", "6", 8);
graph.InsertEdge("3", "7", 5);
graph.InsertEdge("4", "5", 9);
graph.InsertEdge("4", "7", 4);
graph.InsertEdge("5", "7", 3);
graph.InsertEdge("5", "8", 3);
graph.InsertEdge("6", "7", 9);
graph.InsertEdge("7", "8", 5);
Console.WriteLine(graph.printPath(graph.Dijkstra("0", "8")));
*/
/* priority queue run*/
/*
priorityQueue ppqq = new priorityQueue(10);
ppqq.enqueue("1", 1);
ppqq.enqueue("6", 6);
ppqq.enqueue("3", 3);
Console.WriteLine(ppqq.ToString());
ppqq.enqueue("4", 4);
ppqq.enqueue("2", 2);
ppqq.enqueue("5", 5);
Console.WriteLine(ppqq.ToString());
ppqq.dequeue();
Console.WriteLine(ppqq.ToString());
ppqq.dequeue();
Console.WriteLine(ppqq.ToString());
*/
/* Quick Sort run
int[] arr = { 2, 44, 5, 777, 0, 1, -6 };
int[] sorted = QuickSort(arr, 0, arr.Length);
foreach (int i in sorted)
Console.WriteLine(i);
*/
}
public static int[] QuickSort(int[] arr, int start, int end)
{
if (start < end)
{
int pivot = Partion(arr, start, end);
QuickSort(arr, start, pivot);
QuickSort(arr, pivot + 1, end);
}
return arr;
}
public static void Swap(int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static int Partion(int[] arr, int start, int end)
{
int pivot = arr[start];
int swapIndex = start;
for (int i = start; i < end; i++)
{
if (arr[i] < pivot)
{
swapIndex++;
Swap(arr, i, swapIndex);
}
}
Swap(arr, start, swapIndex);
return swapIndex;
}
}
}