I have a linked stack BookStack
which contains Nodes Book
.I need to put the nodes in an Array to be sorted then put back again to stack. Additionally how could I sort alphabetically in C#? How could I implement it?
class Book
{
private string title, author;
private int ISBN;
public Book(string a, string b, int c)
{
title = a;
author = b;
ISBN = c;
}
public string GetAuthor()
{
return author;
}
public string GetTitle()
{
return title;
}
public int GetISBN()
{
return ISBN;
}
}
class NodeStack
{
Node top;
int count;
public void Push(object o)
{
Node newTop = new Node();
newTop.setValue(o);
newTop.setNext(top);
top = newTop;
count++;
}
public object Pop()
{
object value = top.getValue();
top = top.getNext();
return value;
}
public object Peek()
{
return top.getValue();
}
public void Clear()
{
top = null;
count = 0;
}
public int Count()
{
return count;
}
}
Can't think of anything other than toArray(); but it won't work here