1. Linked list¸¦ »ç¿ëÇÏ¿©, QueueÀÇ ¸ðµç ¿¬»êÀ» ±¸ÇöÇϽÿÀ.
Str_queue.h
// ±¸Á¶Ã¼¼±¾ð
struct node
{
int data; // À̸§ ¸ÞÀÏ ÀüȹøÈ£ ¼±¾ð
node *next;// ´ÙÀ½ ³ëµåÀÇ ÁÖ¼Ò¸¦ °¡¸£Å´
};
class queueClass{
public:
queueClass(); //»ý¼ºÀÚÇÔ¼ö
queueClass(const queueClass& s); //º¹»ç»ý¼ºÀÚÇÔ¼ö
~queueClass(); //¼Ò¸êÀÚÇÔ¼ö
void add(int Item); //Item °ªÀ» Å¥¿¡ »ðÀÔ
void remove(); //Å¥ ÇÁ·±Æ®¸¦ »èÁ¦, ¸®ÅÏ°ª ¾øÀ½
int GetSize();
bool IsEmpty(); //ºñ¾î ÀÖ´ÂÁö
bool IsFull(); //²ËÂ÷ ÀÖ´ÂÁö È®ÀÎ
node* rear; //¸¶Áö¸·³ëµå¸¦ °¡¸®Å´
node* temp;
};
Str_queue_c++.cpp
#include "str_queue_h.h"
#include
using namespace std;
queueClass::queueClass() // ÃʱâÈ
{
rear=NULL;
}
queueClass::~queueClass() // ¼Ò¸êÀÚ Á¤ÀÇ
{
while(!IsEmpty())
¡¦(»ý·«)
2. ¿øÇü ¹è¿À» »ç¿ëÇÏ¿©, QueueÀÇ ¸ðµç ¿¬»êÀ» ±¸ÇöÇϽÿÀ.
|
out << "3. Print All"<< endl;
int num;
cin >> num;
if ( num == 1 ){ // ´Ù½Ã µ¥ÀÌÅÍÀÔ·Â ¹Þ±â
cout << " Insert ";
cin >> Temp->data;
Now.add(Temp->data);
}
if ( num == 2 ){ // GetFront ¾Õ µ¥ÀÌÅ͸¦ Ãâ·ÂÇÏ°í Ãâ·ÂµÈ ³ëµå´Â »èÁ¦
printf( " GetFront ");
if(Now.GetSize() == 0) cout << "Empty Data!!" << endl;
else{
cout << Now.rear->next->data << endl;
Now.remove();
}
}
if (num == 3){ // ÀÔ·ÂµÈ µ¥ÀÌÅÍ ¸ðµÎ Ãâ·Â
cout << "Print out All Queue data" << endl;
if (Now.GetSize() == 0){
cout << "Empty data" << endl;
}
else {
Now.temp=Now.rear->next;
for (int i = 1; i<=Now.GetSize(); i++)
{
cout << Now.temp->data << endl;
Now.temp=Now.temp->next;
}
}
}
cout << endl << endl;
}
}
2. ¿øÇü ¹è¿À» »ç¿ëÇÏ¿©, QueueÀÇ ¸ðµç ¿¬»êÀ» ±¸ÇöÇϽÿÀ.
Str_queue_arr_h.h
const int MAX = 100;
// ±¸Á¶Ã¼¼±¾ð
struct node
{
int data; // À̸§ ¸ÞÀÏ ÀüȹøÈ£ ¼±¾ð
node *next; // ´ÙÀ½ ³ëµåÀÇ ÁÖ¼Ò¸¦ °¡¸£Å´
};
class queueClass{
public:
queueClass(); //»ý¼ºÀÚÇÔ¼ö
queueClass(