|
|
|
[ÀڷᱸÁ¶]linked list ÀÌ¿ëÇÏ¿© Queue ±¸Çö ·¹Æ÷Æ® |
|
|
|
|
|
|
|
|
Å°¿öµå : |
|
|
¼Ò°³±Û |
[ÀڷᱸÁ¶]linked list ÀÌ¿ëÇÏ¿© Queue ±¸Çö ·¹Æ÷Æ® |
¿ä¾à |
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()) remove(); }
int queueClass::GetSize(){ //Å¥ÀÇ µ¥ÀÌÅÍÀÇ °¹¼ö¸¦ ¼¼¾îº»´Ù
node* ptr;
int count = 0;
if(rear == NULL) return 0;
else{
ptr=rear->next; while(ptr != rear){
ptr = ptr->next; count++; } }
return (count+1);
}
bool queueClass::IsEmpty(){ // ºñ¾î ÀÖ´ÂÁö
return (re |
|
|
|
|
À§ Á¤º¸¹× °Ô½Ã¹° ³»¿ëÀÇ Áø½Ç¼º¿¡ ´ëÇÏ¿© º¸ÁõÇÏÁö ¾Æ´ÏÇϸç, ÇØ´ç Á¤º¸ ¹× °Ô½Ã¹° ÀúÀ۱ǰú ±âŸ ¹ýÀû Ã¥ÀÓÀº ÀÚ·á µî·ÏÀÚ¿¡°Ô ÀÖ½À´Ï´Ù. À§ Á¤º¸¹× °Ô½Ã¹° ³»¿ëÀÇ ºÒ¹ýÀû ÀÌ¿ë, ¹«´ÜÀüÀç¹× ¹èÆ÷´Â ±ÝÁöµÇ¾î ÀÖ½À´Ï´Ù. ÀúÀÛ±ÇħÇØ, ¸í¿¹ÈÑ¼Õ µî ºÐÀï¿ä¼Ò ¹ß°ß½Ã ÇÏ´ÜÀÇ ÀúÀÛ±Ç Ä§ÇØ½Å°í¸¦ ÀÌ¿ëÇØ Áֽñ⠹ٶø´Ï´Ù. |
|