¿¬½ÀÀå(´Ù¹ö¸®°í °©´Ï´Ù...)-³²±æ ±ÛÀÌ ÀÖÀ¸¸é ¹Î°¡ÃÌ¿¡ ³²°ÜÁֽðí, ȸ¿ø °¡ÀÔÀ» ¹ÞÁö ¾Ê½À´Ï´Ù.

2003/05/16 (04:03) from 61.249.13.17' of 61.249.13.17' Article Number : 60
Delete Modify _Àü Access : 1533 , Lines : 114
Å¥ - ÀÌÁß linked list ÀÌ¿ë
// Å¥ - ÀÌÁß linked list ÀÌ¿ë //

#include
using namespace std;

int MAX_num=0; // ù¹ø° µ¥ÀÌŸ´Â MAX_num=1

struct Link{
int a;
   Link * pre;
Link * next;
};

Link *MY_alloc() // ¸Þ¸ð¸® »ó¿¡ »õ·Î¿î ÁÖ¼Ò »ý¼º
{
Link *temp;
temp=new Link;
temp->pre=NULL;
temp->next=NULL;
return temp;
}

Link * First=NULL ;

void put_q(int i) // µ¥ÀÌŸ µé¾î°¡°í...(¸¶Áö¸·¿¡ Ãß°¡)
{ // ¸Þ¸ð¸® ¿©À¯ Çѵµ±îÁö ÀúÀå
// **. ==> ¸Þ¸ð¸® Ç®À̳ª ÀÔ·ÂÀÌ ÇÑÁ¤µÉ °æ¿ì´Â ¼öÁ¤ ÇÊ¿ä !

Link * Now;
Link * temp; temp = MY_alloc();

while(First)
{
while( First->next )
{
Now=First->pre; Now->next=temp; First->pre=temp;
temp->a=i; temp->pre=Now; temp->next=First; MAX_num ++; return ;
}
temp->a=i; temp->pre=temp->next=First;
         First->pre=First->next=temp; MAX_num ++; return; //  ¸ÇóÀ½ +1
}
temp->a=i; First=temp; MAX_num ++; return ; // ¸ÇóÀ½ µ¥ÀÌŸ »ý¼º
}

int get_q(void) // µ¥ÀÌŸ ³ª¿À°í...(¾Õ¿¡¼­ ºÎÅÍ ³ª¿À°í Áö¿ì°í)
{
int i;
Link * temp;

while(First)
{ i=First->a;
while(First->next)
{
if(First->next!=First->pre)
{
First->pre->next=First->next;
First->next->pre=First->pre; temp=First; First=First->next;  
delete temp; MAX_num--; return i;
}
temp=First; First=First->next; First->pre=NULL; First->next=NULL;
delete temp; MAX_num--; return i; // ³²´Â µ¥ÀÌŸ°¡ 1ÀÏ ¶§
}
delete First; First=NULL; MAX_num --; return i; // ³²´Â µ¥ÀÌŸ°¡ ¾øÀ» ¶§
}
return -1; // "underflow...!!"
}

void view_q(void) // µ¥ÀÌŸ È®ÀÎ
{
int i;
Link * temp;

while (First)
{
temp=First;
cout << "*total = " << MAX_num << " [ ";
   
for(i=1; i {
cout << temp->a << " "; temp=temp->next;
} cout << temp->a;
cout << " ]" << endl; return;
}
cout << "Ãâ·ÂÇÒ µ¥ÀÌŸ°¡ ¾ø½À´Ï´Ù." << endl; return;
}

int main()
{
int i;
   cout << "ÀÚ·á°¡ ¾ø´Â óÀ½»óÅ ȮÀÎ " << get_q() << endl;
view_q();

for(i=1; i<11; i++)
{
put_q(i);
}   view_q();

cout << "get = " << get_q() << endl; view_q();

cout << "put_q(11)   "<< endl;  put_q(11) ; view_q();
cout << "put_q(12)   "<< endl;  put_q(12) ; view_q();
cout << "put_q(13)   "<< endl;  put_q(13) ; view_q();

for(i=0; i<5; i++)
{
cout << "get = " << get_q() << endl;
} view_q();

cout << "put_q(14)   "<< endl;  put_q(14) ; view_q();
cout << "put_q(15)   "<< endl;  put_q(15) ; view_q();
cout << "put_q(16)   "<< endl;  put_q(16) ; view_q();

return 0;
}

Backward Forward Post Reply List