== 작성자의 말 == * 1학년때 엄한 방법으로 짠 스택과 큐를 다시 제대로 링크드리스트를 이용해서 짜보자! * 스택은 자료구조 숙제 겸사겸사 해서 완료. 큐는 조만간 다시 만들 예정. == 스택 == {{{ #include #include using namespace std; struct Node { string data; Node * next; }; void push(Node **top, string argData); string pop(Node **top); string peek(Node *top); void erase(Node **top); void display(Node *top); int main() { Node * top=NULL; //Testing push push(&top, "임영동"); push(&top, "20021035"); push(&top, "컴퓨터공학과"); display(top); //Testing pop cout<<"Pop the top of the node: "<data=argData; temp->next=*top;//Indicate the highest node of stack *top=temp;//Top links to the new element } string pop(Node **top) { Node * temp; string tempData; temp=*top; if(temp==NULL) {//If your stack is empty cout<<"Stack is empty now."<data; *top=temp->next; delete temp; return tempData; } } string peek(Node *top) { string tempData; if(top==NULL) {//If your stack is empty cout<<"Stack is empty now."<data; return tempData; } } void erase(Node **top) { Node *temp; if(*top==NULL) {//If your stack is empty cout<<"Stack is empty now."<next; delete temp; } } void display(Node *top) { cout<<"----Stack----"<data<<"\n"; if(tempNode->next==NULL)//Exit from do-while loop if value of next node is null break; else //Go to the next node if there is next node tempNode=tempNode->next; } }while(1); } }}} == 큐 == {{{~cpp #include int num=0;//현재 사용중인 항목들의 수 int erase_num=0;//지운 항목 수를 세기 위한 수 int i; class List{ private: int data;//항목이 가진 값 List * next;//다음 항목을 가리키는 포인터 public: List(); List(int); ~List(); void add(int, List *); void erase(List *); void show(); void last(List *);//link와 last 메서드는 맨 마지막 항목의 void link(List *);//다음 항목을 가리키는 포인터를 NULL로 만들기 위한 함수 }; List::List() { data=0; next=NULL; } List::List(int temp) { data=temp; next=NULL; } List::~List() { delete next; } void List::add(int temp, List *n) { data=temp; next=n; num++; cout<next=this; next=NULL; } void List::link(List *n) { next=n; } int main() { int input, sub_input1; List * list=new List[10]; //우선 10개 동적 할당 do{ cout<<"==================LINKED LIST======================"<>input; switch(input){ case 1: if(num==10) cout<<"더 이상 추가할 수 없습니다.n"; else{ cout<<"추가할 항목의 값은? "; cin>>sub_input1; list[num].add(sub_input1, &list[num+1]); list[num-1].last(&list[num-2]); for(i=erase_num;i