#include <iostream>
using namespace std;
class DNode {
friend class MyStruct;
private:
int data;
DNode *prev;
DNode *next;
};
class MyStruct {
private:
DNode* first;
DNode* last;
public:
MyStruct() {
first = new DNode();
last = new DNode();
first->prev = last->next = NULL;
first->next = last;
last->prev = first;
}
~MyStruct() {
DNode* temp1 = first, *temp2;
while (temp1 != last) {
temp2 = temp1;
temp1 = temp1->next;
delete temp2;
}
delete temp1;
}
void pushFront(int data) {
DNode* temp = new DNode();
temp->data = data;
temp->next = first->next;
first->next->prev = temp;
temp->prev = first;
first->next = temp;
cout << " front 삽입 : " << data << endl;
}
int popFront()
{
// ★ -----------------------------------------------------------------------
// 이 부분을 삭제하고 popFront() 함수를 완성하시오.
cout << "현재는 자료를 빼올 수가 없습니다. " << endl;
return -1;
// ★ -----------------------------------------------------------------------
}
void pushBack(int data) {
DNode* temp = new DNode();
temp->data = data;
temp->prev = last->prev;
last->prev->next = temp;
temp->next = last;
last->prev = temp;
cout << " back 삽입 : " << data << endl;
}
int popBack() {
// ★ -----------------------------------------------------------------------
// 이 부분을 삭제하고 popBack() 함수를 완성하시오.
cout << "현재는 자료를 빼올 수가 없습니다. " << endl;
return -1;
// ★ -----------------------------------------------------------------------
}
};
int main(void)
{
MyStruct myStruct;
myStruct.pushFront(10);
myStruct.popFront();
myStruct.popFront();
myStruct.pushFront(20);
myStruct.pushFront(30);
myStruct.popFront();
myStruct.popBack();
myStruct.pushBack(90);
myStruct.popBack();
myStruct.popBack();
myStruct.pushBack(100);
myStruct.pushBack(110);
myStruct.popBack();
getchar();
}
자료구조 공부중인데
c++을 아예 몰라서 작성을 못하겠습니다.
popFront
popBack
어떻게 작성해야 하나요???