Compare commits
4 Commits
e66473bb25
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
0dfb647f8f | |||
e2157e7093 | |||
78ac09c4e9 | |||
a37a81a2bf |
44
Datastructures/Heap/Heap.cs
Normal file
44
Datastructures/Heap/Heap.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C_.Datastructures.Heap
|
||||
{
|
||||
internal class Heap<T> where T:IComparable
|
||||
{
|
||||
internal HeapNode<T>? Root { get; set; }
|
||||
private int Count { get; set; }
|
||||
|
||||
public static Heap<T> Create(){
|
||||
return new Heap<T>{
|
||||
Root = null,
|
||||
Count = 0
|
||||
};
|
||||
}
|
||||
|
||||
public static Heap<T> Create(T value){
|
||||
return new Heap<T>{
|
||||
Root = HeapNode<T>.Create(value),
|
||||
Count = 1
|
||||
};
|
||||
}
|
||||
|
||||
public void Add(T value){
|
||||
Count++;
|
||||
|
||||
if (Root == default)
|
||||
{//If the new node needs to be added to the top of the heap
|
||||
Root = HeapNode<T>.Create(value);
|
||||
return;
|
||||
}
|
||||
|
||||
//If the new node can be placed in a subchild
|
||||
HeapNode<T> node = Root;
|
||||
|
||||
while(node.Left != default){
|
||||
node = node.Left;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using C_.Datastructures.DoublyLinkedList;
|
||||
using C_.Datastructures.BinaryTree;
|
||||
using C_.Datastructures.Heap;
|
||||
|
||||
@@ -38,6 +39,8 @@ Console.WriteLine("Hello, World!");
|
||||
// list.Append(6);
|
||||
// list.Insert(6, 1);
|
||||
|
||||
// list.Delete(0);
|
||||
|
||||
// Console.Write($"{list[0]} ");
|
||||
// Console.Write($"{list[1]} ");
|
||||
// Console.Write($"{list[2]} ");
|
@@ -1,6 +1,6 @@
|
||||
# DataStructures
|
||||
|
||||
List of DataStructures implemented in C#, Go And C++
|
||||
List of DataStructures implemented in C#
|
||||
|
||||
## What is Included
|
||||
|
||||
@@ -11,7 +11,7 @@ Doubly Linked List
|
||||
Stack
|
||||
Queue
|
||||
Binary Tree
|
||||
Heap
|
||||
Heap ~
|
||||
|
||||
### Algorithms
|
||||
|
||||
|
Reference in New Issue
Block a user