1

I am stuck in sorting really want a code that can sort my dynamic stack i am posting my code if anyone can help me provide me code for sorting according to my code.

class Node
{
    public int info; //incoming data
    public Node link; //reference of next value

    public Node(int i)
    {
        info = i;
        link = null;
    }
}

class DynamicStack
{
    private Node start;
    public DynamicStack()
    {
        start = null;
    }
    public void Push(int data)
    {
        Node temp = new Node(data);
        temp.link = start;
        start = temp;
    }
    public void CreateStack()
    {
        int i, n, data;
        Console.Write("Enter the number of nodes : ");
        n = Convert.ToInt32(Console.ReadLine());
        if (n == 0)
            return;
        for (i = 1; i <= n; i++)
        {
            Console.Write("Enter the element to be inserted : ");
            data = Convert.ToInt32(Console.ReadLine());
            Push(data);
        }
    }
    public void Pop()
    {
        if (start == null)
            return;
        start = start.link;
    }

By using these methods i can push and pop my values in list but stuck in sorting those inserted values just need a code which can work with my code and sort my values.

  • Possible duplicate of [Merge Sort a Linked List](https://stackoverflow.com/questions/7685/merge-sort-a-linked-list) – bunglehead Nov 25 '18 at 11:30

0 Answers0