Created Stack class + Creation Methods
This commit is contained in:
		
							
								
								
									
										24
									
								
								C#/Datastructures/Stack.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								C#/Datastructures/Stack.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
using C_.Datastructures.Nodes;
 | 
			
		||||
 | 
			
		||||
namespace C_.Datastructures
 | 
			
		||||
{
 | 
			
		||||
    internal class Stack<T>
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        public StackNode<T>? Head { get; set; }
 | 
			
		||||
        public int Count { get; set; }
 | 
			
		||||
 | 
			
		||||
        public Stack<T> Create(){
 | 
			
		||||
            //Create a new stack without a head
 | 
			
		||||
            return new Stack<T>{ Head = default, Count = 0};
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Stack<T> Create(T value){
 | 
			
		||||
            //Create a new Stack with a head
 | 
			
		||||
            return new Stack<T>{
 | 
			
		||||
                Head = new StackNode<T>{Value = value, Next = default},
 | 
			
		||||
                Count = 1
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user