2011. 12. 23. 00:52
//DoubleLinkedList.cpp
//2011 12 22
//Daun 
//넣고 출력하는기능밖에 없음 
#include<iostream>
using namespace std;

class Node
{
public:
Node()
{
beforeNode=0;
afterNode=0;
num = 0;
}
int num;
Node *beforeNode;
Node *afterNode;
};
class Manage
{
public:
Manage()
{
firstNode = new Node;
newNode = new Node;
newNode->beforeNode = firstNode;
firstNode->afterNode = newNode;
}
void make(int temp)
{
Node *nowNode = firstNode;
nowNode = nowNode->afterNode;

while(nowNode->num != 0 )
nowNode = nowNode->afterNode;

Node *newNode = new Node;
nowNode->num = temp;
nowNode->afterNode = newNode;
newNode->beforeNode = nowNode;
}
void printFirst()
{
Node *nowNode = firstNode;
nowNode = nowNode->afterNode;
while(nowNode->num != 0 )
{
cout << nowNode->num << endl;
nowNode = nowNode->afterNode;
}
}
void printLast()
{
Node *nowNode = firstNode;
nowNode = nowNode->afterNode;
while(nowNode->num != 0 )
nowNode = nowNode->afterNode;

nowNode = nowNode->beforeNode;

while(nowNode->num !=0)
{
cout << nowNode->num << endl;
nowNode = nowNode->beforeNode;
}
}
private:
Node *firstNode;
Node *newNode;
};
int main()
{
int type;
Manage ma;
while(1)
{
type = 0;
cout << "press the type" << endl;
cout << "1 : insert, 2 : print from first , 3 : print from last" << endl;
cin >> type;
switch(type)
{
case 1:
int temp;
cout << "write the number without '0'"<<endl;;
cin >> temp;
ma.make(temp);
break;
case 2:
ma.printFirst();
break;
case 3:
ma.printLast();
break;
}
}
return 0;
}

'Code > c/c++' 카테고리의 다른 글

[C++]연산자오버로딩  (0) 2012.02.11
[C++]Game of Snake.  (0) 2011.09.03
[C++]poker  (0) 2011.09.03
[Code] 유클리드 알고리즘(Euclid Algorism)  (0) 2011.08.29
[C++ Code]Swap  (0) 2011.07.28
Posted by I_co