Skip to content

Commit 347a5d8

Browse files
committed
Implement Stack
1 parent 82dc8c4 commit 347a5d8

File tree

5 files changed

+45
-144
lines changed

5 files changed

+45
-144
lines changed

.editorconfig

Lines changed: 0 additions & 8 deletions
This file was deleted.

CSharpAlgorithms.DataStructures/graph/Graph.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ namespace CSharpAlgorithms.DataStructures.graph
66
{
77
class Graph
88
{
9+
910
}
1011
}

CSharpAlgorithms.DataStructures/stack/Stack.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,50 @@
44

55
namespace CSharpAlgorithms.DataStructures.stack
66
{
7-
class Stack
7+
public class Stack
88
{
9+
public linked_list.LinkedList list { get; set; }
10+
11+
public Stack()
12+
{
13+
list = new linked_list.LinkedList();
14+
}
15+
16+
public bool IsEmpty()
17+
{
18+
return list.Tail == null;
19+
}
20+
21+
public object Peek()
22+
{
23+
if(list.Tail == null){
24+
return null;
25+
}
26+
return list.Tail.Item;
27+
}
28+
public void Push(object item)
29+
{
30+
list.Append(item);
31+
}
32+
public object Pop()
33+
{
34+
var removedTail = list.DeleteTail();
35+
if(removedTail == null)
36+
{
37+
return null;
38+
}
39+
return removedTail.Item;
40+
}
41+
public object[] ToArray()
42+
{
43+
var reversedList = list.ToList();
44+
reversedList.Reverse();
45+
return reversedList.ToArray();
46+
}
47+
public override string ToString()
48+
{
49+
return list.ToString();
50+
}
51+
952
}
1053
}

CSharpAlgorithms.DataStructures/stack/Stack.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

CSharpAlgorithms.DataStructures/stack/__test__/Stack.test.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)