我有一个包含节点BookStack
的链接堆栈Book
。我需要将节点放在一个数组中进行排序然后再放回堆栈。另外,我如何在C#中按字母顺序排序?我怎么能实现它?
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;
}
}
除了toArray()之外,别想其他事情;但它不会在这里工作