음...메인의 주석 된 부분을 제거하면 에러가 납니다......어떻게 해야 에러가 안날까요 ..ㅠ 에러의 내용은
nresolved external symbol "public: __thiscall List::List(void)" (??0List@@QAE@XZ)
이렇게 나오네요...
#include <iostream.h>
#include <string.h>
class Node
{
private:
int data;
Node *next;
Node *prev;
Node (int val)
{data = val; next = 0; prev = 0;}
friend class List;
};
class List {
private:
Node *head;
public:
List();
~List();
void insertList(int);
void deleteList(int);
void forwardList();
void backwardList(); void searchList(int);
void displayList(); int isEmpty();
};
void main(){
// List l1;
//l1.insertList(50);
}
int List::isEmpty() { return (head == 0); }
void List::insertList(int data)
{
Node *temp = new Node(data);
Node *p, *q;
if (head == 0) // 첫노드일때
head = temp;
else if (temp->data < head->data) { //head node 앞에 삽입
temp->next = head;
head->prev = temp;
head = temp;
}
else { // 가운데 삽입
p = head;
q = head;
while ((p != 0) && (p->data < temp->data)) {
q = p;
p = p->next;
}
if (p != 0) {
temp->next = p;
temp->prev = q;
q->next = temp;
p->prev = temp;
}
else {
q->next = temp;
temp->prev = q;
}
}
}
void List::deleteList(int key)
{
Node *p, *q;
if (head->data == key) { // 삭제될 노드가 head 일 경우
p = head;
head = head->next;
head->prev = 0;
delete p;
}
else { // 가운데 노드가 삭제될 경우
q = head;
p = head;
while (p != 0 && p->data != key) {
q = p;
p = p->next;
}
if (p != 0) {
q->next = p->next;
if (p->next != 0)
p->next->prev = q;
delete p;
}
// 마지막 노드일경우
else
cout << key << " is not in the listn";
}
}
void List::forwardList()
{
if (!isEmpty()) {
Node *p = head;
cout << "----- Forward List -----n";
while (p!= 0) {
cout << p->data << endl;
p = p->next;
}
}
else
cout << "List is empty!n";
}
void List::backwardList()
{
if (!isEmpty()) {
Node *p = head;
while (p->next != 0)
p = p->next;
cout << "----- Backward List -----n";
while (p!= 0) {
cout << p->data << endl;
p = p->prev;
}
}
else
cout << "List is empty!n";
}
void List::searchList(int key)
{
if (!isEmpty()) {
Node *p = head;
while (p != 0 && p->data != key)
p = p->next;
if (p != 0)
cout << p->data << " is in the listn";
else
cout << key << " is not int the listn";
}
else
cout << "List is empty!n";
}
List::~List()
{
Node *p;
while (head != 0) {
p = head;
head = head->next;
delete p;
}
}