我试图弄清楚确定单链表是否为空的最佳和最简单的方法是什么。
我需要创建一个布尔方法吗?
谢谢
读取方法
无效列表::读取(istream&r){
char c[13];
r >> c;
r >> numberOfInts;
Node *node = new Node();
for(int i = 0; i < numberOfInts; i++)
{
r >> node->data;
cout << node->data << endl;
node->next = new Node;
//node = node->next;
head = node;
}
}
else
{
if(node->data > head->data)
{
head->next;
}
else if(node->data < head->data)
{
Node* tempNode;
tempNode = head;
head->data = node->data;
node->data = tempNode->data;
}
}
system("pause");
}
头文件
class Node
{
public:
Node() {}
Node(int d, Node* q = 0) : data(d), next(q) {} //constructor with parameters data and next
int data; //holds data in node
Node* next;//pointer to next node
};
class List
{
public:
void Read(istream&);
void Write(ostream&);
void setReadSort(bool);
void sortOwn();
void insertionSort(Node*);
bool isEmpty();
bool _sortRead;
int numberOfInts;
List(void);
~List(void);
protected:
Node *head;
Node current;
};