C# OOP: Stack

Stack item and operations

Step 1: Defining Stack item and methods Each item of the Stack contains two parts. One part is to store the integer value and another part to store the address of its next item.

class ListNode<T>{ //T is a generic type
 ListNode(T elem) { val = elem; next = null; }
 public T val; //node data
 public ListNode<T> next;//next link
}

//---------------------------------------------------------
The operations associated with the Stack data structure can be outlined as the methods in the abstract class ClsList as shown below:


abstract class ClsList<T>{
 protected ListNode<T> pfirst; //stores the first element
 protected ListNode<T> plast; //stores the last element

public ListNode<T> push(){
 return null;
}

public int countitem(){
 return 0;
}

public ListNode<T> pop(){
 return null;
}

public void printall(){

}

public ListNode<T> find(T tar){
 return null;
}

public ListNode<T> findmin(){
 return null;
}
public ListNode<T> findmax(){
 return null;
}


}

This abstract class is inherited by our main Stack class. You will find the code implementations of the methods in the next subsequent steps. See the left hand menu to find their links.




Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.