/* Time Check Program of B Tree Operation. */ ///////////////////////////////////////////////////////////////////////////////////////// /************************************* pRoGrAm sTaRt ***********************************/ ///////////////////////////////////////////////////////////////////////////////////////// /*=====================================================================================*/ /************************************* PREPROCESSOR ************************************/ /*=====================================================================================*/ #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define STR_MAX 30 /*=====================================================================================*/ /*************************** TYPE DEFINITION (STRUCTURE & ENUM) ************************/ /*=====================================================================================*/ typedef struct tree *tree_ptr; // structure pointer definition of trees typedef struct tree{ // structure definition of trees tree_ptr left, middle, right; // link member int key1, key2; // key member }tree; typedef struct stack *stk_ptr; // structure pointer definition of stack typedef struct stack{ // structure definition of stack tree_ptr ads; // address member(address of visited node) stk_ptr link; // link member }stack; typedef struct queue *que_ptr; // structure pointer definition of queue typedef struct queue{ // structure definition of queue tree_ptr ads; // address member(address of node) que_ptr link; // link member }queue; /*=====================================================================================*/ /****************************** GLOVAL VARIABLE DECLARATION ****************************/ /*=====================================================================================*/ tree_ptr root; // root node of B+ tree(auto initial : NULL) stk_ptr stk_top; // head node of stack(auto initial : NULL) LARGE_INTEGER Frequency; // variable for time check LARGE_INTEGER BeginTime; // variable for time check LARGE_INTEGER Endtime; // variable for time check /*=====================================================================================*/ /********************************* PROTOTYPE OF FUNCTION *******************************/ /*=====================================================================================*/ void initial_creator(char name[]); void insertion(int in_key); void deletion(int out_key); void selection(int key); void update(int key1, int key2); void data_view(); void stack_push(tree_ptr ads); tree_ptr stack_pop(); void queue_insert(que_ptr *front, que_ptr *rear, tree_ptr ads); tree_ptr queue_delete(que_ptr *front); void delay(clock_t sleep); /*=====================================================================================*/ /************************************ main() FUNCTION **********************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> ÇÁ·Î±×·¥ÀÇ Àü¹ÝÀûÀÎ È帧Á¦¾î¿Í ÇÊ¿äÇÑ ¼­ºêÇÔ¼ö¸¦ È£ÃâÇÏ¿© ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> insertion(), deletion(), selection(), update(), data_view() */ void main(void){ /* local variable declaration */ __int64 elapsed; // variable for time check double duringtime; // variable for time check char buf[STR_MAX], op[10]; int key1, key2; QueryPerformanceFrequency(&Frequency); printf("==========================================\n"); // main title printf("| TIME CHECK PROGRAM OF B TREE OPERATION |\n"); printf("==========================================\n"); printf(">> INPUT FILE NAME FOR INITIAL CREATION : "); gets(buf); initial_creator(buf); // initial creation do{ printf("\n>>> INPUT COMMAND(insert/delete/update/select/show/exit) <<<\n"); printf("COMMAND>> "); gets(buf); sscanf(buf, "%s", op); QueryPerformanceCounter(&BeginTime); // start time check //================================================================ if(!strcmp(op, "insert")){ // insertion operation sscanf(buf, "%s%d", op, &key1); insertion(key1); } else if(!strcmp(op, "delete")){ // deletion operation sscanf(buf, "%s%d", op, &key1); deletion(key1); } else if(!strcmp(op, "select")){ // selection operation sscanf(buf, "%s%d", op, &key1); selection(key1); } else if(!strcmp(op, "update")){ // update operation sscanf(buf, "%s%d%d", op, &key1, &key2); update(key1, key2); } else if(!strcmp(op, "show")) data_view(); // show operation else if(!strcmp(op, "exit")){ // program exit printf("\nPrOgRaM EnD...ByE...\n\n"); exit(1); } else printf("\n UNCORRECT COMMAND!!!\n\a"); //================================================================= QueryPerformanceCounter(&Endtime); // end time check elapsed = Endtime.QuadPart - BeginTime.QuadPart; duringtime = (double)elapsed / (double)Frequency.QuadPart; printf("\nEXHAUSTED TIME : %f SEC\n", duringtime); // exhausted time print }while(1); } /*=====================================================================================*/ /******************************* initial_creator() FUNCTION ****************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> Ãʱ⠵¥ÀÌÅÍÀÇ »ý¼º ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> insertion() */ void initial_creator(char name[]){ __int64 elapsed; // variable for time check double duringtime; // variable for time check char buf[STR_MAX]; FILE *in_fp; int key; if((in_fp = fopen(name, "r")) == NULL){ printf("\n FILE OPEN ERROR!!!\n\a"); exit(1); } while(fgets(buf, STR_MAX, in_fp) != NULL){ // ÁÙ ´ÜÀ§·Î ÀúÀåÇÔ sscanf(buf, "%d", &key); // ¼ýÀÚ·Î ÀúÀå½ÃÅ´ QueryPerformanceCounter(&BeginTime); // start time check insertion(key); // insertion() function call QueryPerformanceCounter(&Endtime); // end time check elapsed = Endtime.QuadPart - BeginTime.QuadPart; duringtime = (double)elapsed / (double)Frequency.QuadPart; printf("\nEXHAUSTED TIME : %f SEC\n", duringtime); // exhausted time print } } /*=====================================================================================*/ /********************************** insertion() FUNCTION *******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> B TreeÀÇ »ðÀÔ ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> NONE */ void insertion(int key){ /* local variable declaration */ tree_ptr temp, tmp1, tmp2, new_node; // temporary space int Found=FALSE, Finished; // falg variable int k[3]; // temporary space //============================================================== work start if(!root){ // óÀ½ »ðÀÔÀÏ °æ¿ì temp=(tree_ptr)malloc(sizeof(tree)); // dynamic allocation temp->key1=key; temp->key2=INT_MAX; temp->left=temp->middle=temp->right=NULL; // ¸µÅ©°ªÀÇ ÃʱâÈ­ root=temp; return; } temp=root; // address assignment delay(1); // program delay do{ stack_push(temp); // stack push if((key==temp->key1) || (key==temp->key2)){ // °°Àº Ű °ªÀ» ¹ß°ßÇßÀ» ¶§ Found=TRUE; break; } if(!temp->left){ // leaf³ëµåÀÏ °æ¿ì stack_pop(); // stack pop break; } else{ // leaf³ëµå°¡ ¾Æ´Ò °æ¿ì °æ·Î¸¦ µû¶ó°¨ if(key < temp->key1) temp=temp->left; // move to left else if(key > temp->key1 && key < temp->key2) temp=temp->middle; // move to middle else temp=temp->right; // move to right } }while(!Found); if(Found){ // °°Àº Ű °ªÀÌ ÀÌ¹Ì Æ®¸®¿¡ Á¸ÀçÇÒ °æ¿ì printf("\n ALREADY EXIST SAME KEY!!!\n\a"); return; } else{ // °°Àº Ű °ªÀÌ Æ®¸®¿¡ ¾øÀ» °æ¿ì --> »ðÀÔ ½ÃÀÛ Finished=FALSE; // Finishedº¯¼öÀÇ ÃʱâÈ­ do{ if(temp->key2==INT_MAX){ // ÇöÀç ³ëµå¿¡ ºó°ø°£ÀÌ ÀÖÀ» °æ¿ì if(key > temp->key1){ if(temp->left) temp->right=tmp2; temp->key2=key; // Ű °ªÀÇ ¼ø¼­¸¦ À¯ÁöÇϸ鼭 ÀûÀýÈ÷~~~ »ðÀÔ } else{ temp->key2=temp->key1; temp->key1=key; if(temp->left){ temp->right=temp->middle; temp->middle=new_node; } } Finished=TRUE; // Finishedº¯¼ö¸¦ TRUE·Î ¸¸µé¾î ·çÇÁ¸¦ ºüÁ®³ª¿Â´Ù. } else{ // ÇöÀç ³ëµå¿¡ ºó°ø°£ÀÌ ¾øÀ» °æ¿ì if(key < temp->key1){ k[0]=key; k[1]=temp->key1; k[2]=temp->key2; } else if(key > temp->key1 && key < temp->key2){ k[0]=temp->key1; k[1]=key; k[2]=temp->key2; } else{ k[0]=temp->key1; k[1]=temp->key2; k[2]=key; } temp->key1=k[0]; temp->key2=INT_MAX; // value save new_node=(tree_ptr)malloc(sizeof(tree)); // dynamic allocation new_node->key1=k[2]; new_node->key2=INT_MAX; // value save if(temp->left){ // leaf°¡ ¾Æ´Ò °æ¿ì if(temp->middle->key1 > tmp2->key1){ new_node->left=temp->middle; new_node->middle=temp->right; new_node->right=NULL; // link save temp->right=NULL; temp->middle=tmp2; } else if(temp->right->key1 < new_node->key1){ new_node->left=temp->right; new_node->middle=tmp2; new_node->right=NULL; // link save temp->right=NULL; } else{ new_node->left=tmp2; new_node->middle=temp->right; new_node->right=NULL; // link save temp->right=NULL; } } else new_node->left=new_node->middle=new_node->right=NULL; // link save tmp2=new_node; // address assignment if(stk_top){ // STACKÀÇ TOPÀÌ NULLÀÌ ¾Æ´Ò °æ¿ì temp=stack_pop(); key=k[1]; } else{ // STACKÀÇ TOPÀÌ NULLÀÏ °æ¿ì --> Æ®¸®ÀÇ ·¹º§ÀÌ 1Áõ°¡ tmp1=(tree_ptr)malloc(sizeof(tree)); // dynamic allocation tmp1->key1=k[1]; tmp1->key2=INT_MAX; // value save tmp1->left=temp; tmp1->middle=new_node; tmp1->right=NULL; // link save root=tmp1; // address assignment Finished = TRUE; } } }while(!Finished); } while(stk_top) temp=stack_pop(); // STACK°ø°£À» RELEASEÇϰí TOPÀ» ÃʱâÈ­ stk_top = NULL; // ½ºÅÃÀÇ Àç ÃʱâÈ­ } /*=====================================================================================*/ /********************************** deletion() FUNCTION ********************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> B TreeÀÇ »èÁ¦ ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> NONE */ void deletion(int key){ /* local variable declaration */ int Found=FALSE, Finished; // falg variable tree_ptr temp, tmp1, tmp2, tmp3; // temporary space int num_t; //============================================================== work start if(!root){ // °ø Æ®¸®ÀÏ °æ¿ì printf("\n TREE IS EMPTY!!!\n\a"); return; } temp=root; // address assignment delay(1); // program delay do{ stack_push(temp); // stack push if((key==temp->key1) || (key==temp->key2)){ // °°Àº Ű °ªÀ» ¹ß°ßÇßÀ» ¶§ if(!temp->left) stack_pop(); Found=TRUE; break; } else{ // ÇöÀç ³ëµå¿¡ »èÁ¦Å° °ª°ú °°Àº ۰ªÀÌ ¾øÀ» °æ¿ì °æ·Î¸¦ µû¶ó°¨. if(key < temp->key1) temp=temp->left; // move to left else if(key > temp->key1 && key < temp->key2) temp=temp->middle; // move to middle else temp=temp->right; // move to right } if(!temp) break; // °°Àº Ű °ªÀ» ¹ß°ßÇÏÁö ¸øÇßÀ» °æ¿ì ·çÇÁ¸¦ ºüÁ®³ª°¨ }while(!Found); if(!temp && !Found){ // »èÁ¦ÇÒ Å° °ª°ú °°Àº Ű °ªÀÌ ¾øÀ» °æ¿ì printf("\n OUT_KEY IS NOT EXIST IN TREE\n\a"); return; } Finished=FALSE; // Finishedº¯¼öÀÇ ÃʱâÈ­ do{ if(!temp->left){ // »èÁ¦Å°°¡ leaf¿¡ ÀÖÀ» °æ¿ì if(temp->key2!=INT_MAX){ // »èÁ¦Å°¸¦ °¡Áø ³ëµå°¡ µÎ °³ÀÇ Å°¸¦ °¡Áú °æ¿ì if(key==temp->key1) temp->key1=temp->key2; temp->key2=INT_MAX; Finished=TRUE; } else{ // »èÁ¦Å°¸¦ °¡Áø ³ëµå°¡ ÇÑ °³ÀÇ Å°¸¦ °¡Áú °æ¿ì(¾ð´õÇÃ·Î¿ì ¹ß»ý)======================== if(stk_top){ // STACKÀÇ TOPÀÌ NULLÀÌ ¾Æ´Ò °æ¿ì tmp1=stack_pop(); // stack pop if(tmp1->middle->key1==temp->key1){ // »èÁ¦Å° °ªÀÌ Áß°£ ÀÚ½ÄÀÏ °æ¿ì tmp2=tmp1->left; tmp3=tmp1->right; // address assignment if(tmp2->key2!=INT_MAX){ // ¿ÞÂÊ ÀÎÁ¢ÇüÁ¦³ëµå°¡ µÎ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÀçºÐ¹è) temp->key1=tmp1->key1; tmp1->key1=tmp2->key2; tmp2->key2=INT_MAX; } else{ // ¿ÞÂÊ ÀÎÁ¢ÇüÁ¦³ëµå°¡ ÇÑ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì if(tmp1->key2!=INT_MAX){ // ºÎ¸ð³ëµå°¡ µÎ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÇÕº´) tmp2->key2=tmp1->key1; tmp1->key1=tmp1->key2; tmp1->key2=INT_MAX; tmp1->middle=tmp3; tmp1->right=NULL; free(temp); } else{ // ºÎ¸ð³ëµå°¡ ÇÑ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÇÕº´) tmp1->key2=tmp1->key1; tmp1->key1=tmp2->key1; tmp1->left=tmp1->middle=tmp1->right=NULL; free(temp); free(tmp2); } } } else if(tmp1->left->key1==temp->key1){ // »èÁ¦Å° °ªÀÌ ¿ÞÂÊ ÀÚ½ÄÀÏ °æ¿ì tmp2=tmp1->middle; tmp3=tmp1->right; // address assignment if(tmp2->key2!=INT_MAX){ // ÀÎÁ¢ÇüÁ¦³ëµå°¡ µÎ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÀçºÐ¹è) temp->key1=tmp1->key1; tmp1->key1=tmp2->key1; tmp2->key1=tmp2->key2; tmp2->key2=INT_MAX; } else{ // ÀÎÁ¢ÇüÁ¦³ëµå°¡ ÇÑ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì if(tmp1->key2!=INT_MAX){ // ºÎ¸ð³ëµå°¡ µÎ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÇÕº´) tmp2->key2=tmp2->key1; tmp2->key1=tmp1->key1; tmp1->key1=tmp1->key2; tmp1->key2=INT_MAX; tmp1->left=tmp2; tmp1->middle=tmp3; tmp1->right=NULL; free(temp); } else{ // ºÎ¸ð³ëµå°¡ ÇÑ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÇÕº´) tmp1->key2=tmp2->key1; tmp1->left=tmp1->middle=tmp1->right=NULL; free(temp); free(tmp2); } } } else if(tmp1->right->key1==temp->key1){ // »èÁ¦Å° °ªÀÌ ¿À¸¥ÂÊ ÀÚ½ÄÀÏ °æ¿ì tmp2=tmp1->middle; tmp3=tmp1->left; // address assignment if(tmp2->key2!=INT_MAX){ // ÀÎÁ¢ÇüÁ¦³ëµå°¡ µÎ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÀçºÐ¹è) temp->key1=tmp1->key2; tmp1->key2=tmp2->key2; tmp2->key2=INT_MAX; } else{ // ÀÎÁ¢ÇüÁ¦³ëµå°¡ ÇÑ °³ÀÇ Å° °ªÀ» °¡Áú °æ¿ì(ÇÕº´) tmp2->key2=tmp1->key2; tmp1->key2=INT_MAX; tmp1->right=NULL; free(temp); } } else{ // ¾Æ¹«°Íµµ ¾Æ´Ò°æ¿ì ---Ä¡¸íÀû ¿À·ù printf("\n !!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\a"); exit(1); } Finished=TRUE; } else{ // STACKÀÇ TOPÀÌ NULLÀÏ °æ¿ì free(temp); root=NULL; Finished=TRUE; } } } else{ // »èÁ¦Å°°¡ ÀϹݳëµå¿¡ ÀÖÀ» °æ¿ì if(temp->key2!=INT_MAX){ // »èÁ¦Å°¸¦ °¡Áø ³ëµå°¡ µÎ °³ÀÇ Å°¸¦ °¡Áú °æ¿ì } else{ // »èÁ¦Å°¸¦ °¡Áø ³ëµå°¡ ÇÑ °³ÀÇ Å°¸¦ °¡Áú °æ¿ì(¾ð´õÇÃ·Î¿ì ¹ß»ý) tmp1=temp->left; while(temp->left){ // leaf³ëµå°¡ ¾Æ´Ò µ¿¾È ·çÇÁ¸¦ ¹Ýº¹ÇÑ´Ù. if(tmp1->key2!=INT_MAX){ // ÁÂÃø ³ëµå°¡ °¡Áø ŰÀÇ °³¼ö°¡ µÎ °³ÀÏ °æ¿ì num_t=temp->key1; temp->key1=tmp1->key2; tmp1->key2=num_t; } else{ // ÁÂÃø ³ëµå°¡ °¡Áø ŰÀÇ °³¼ö°¡ ÇÑ °³ÀÏ °æ¿ì num_t=temp->key1; temp->key1=tmp1->key1; tmp1->key1=num_t; } temp=tmp1; tmp1=temp->left; } } } }while(!Finished); while(stk_top) temp=stack_pop(); // STACK°ø°£À» RELEASEÇϰí TOPÀ» ÃʱâÈ­ stk_top = NULL; // ½ºÅÃÀÇ Àç ÃʱâÈ­ } /*=====================================================================================*/ /********************************** selection() FUNCTION *******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> B TreeÀÇ ¼±Åà ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> NONE */ void selection(int key){ /* local variable declaration */ tree_ptr temp; int Found=FALSE; //============================================================== work start if(!root){ // °ø Æ®¸®ÀÏ °æ¿ì printf("\n TREE IS EMPTY!!!\n\a"); return; } temp=root; // address assignment delay(1); // program delay do{ if((key==temp->key1) || (key==temp->key2)){ // °°Àº Ű °ªÀ» ¹ß°ßÇßÀ» ¶§ Found=TRUE; break; } else{ // ÇöÀç ³ëµå¿¡ »èÁ¦Å° °ª°ú °°Àº ۰ªÀÌ ¾øÀ» °æ¿ì °æ·Î¸¦ µû¶ó°¨. if(key < temp->key1) temp=temp->left; // move to left else if(key > temp->key1 && key < temp->key2) temp=temp->middle; // move to middle else temp=temp->right; // move to right } if(!temp) break; // °°Àº Ű °ªÀ» ¹ß°ßÇÏÁö ¸øÇßÀ» °æ¿ì ·çÇÁ¸¦ ºüÁ®³ª°¨ }while(!Found); if(!temp && !Found){ // »èÁ¦ÇÒ Å° °ª°ú °°Àº Ű °ªÀÌ ¾øÀ» °æ¿ì printf("\n>> (KEY VALUE : %d) IS NOT EXIST IN TREE\n\a", key); return; } else printf("\n>> (KEY VALUE : %d) IS EXIST IN TREE\n", key); //============================================================== work end } /*=====================================================================================*/ /*********************************** update() FUNCTION *********************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> B TreeÀÇ ¼öÁ¤ ÀÛ¾÷À» ¼öÇàÇÏ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> insertion(), deletion() */ void update(int key1, int key2){ //============================================================== work start deletion(key1); // ¼öÁ¤ÇÒ Å° °ª »èÁ¦ insertion(key2); // »õ·Î¿î Ű °ª »ðÀÔ //============================================================== work end } /*=====================================================================================*/ /********************************* data_view() FUNCTION ********************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> B TreeÀÇ ÇöÀç ³»¿ëÀ» Ãâ·ÂÇÏ´Â ÇÔ¼ö(LEVEL ORDER TRAVERSAL) */ /*>>> CALL FUNCTION >>> NONE */ void data_view(){ /* local variable declaration */ que_ptr front=NULL, rear=NULL; // index variable declaration of queue & initial tree_ptr temp = root; // address assignment if(!temp){ // case : empty tree (error message print & return) printf("\n NONE DATA IN TREE\n\a"); return; } queue_insert(&front, &rear, temp); // queue insertion while(1){ temp = queue_delete(&front); // queue deletion printf("\n"); if(temp){ // case : temp != NULL if(temp->key1!=INT_MAX) printf("%d ", temp->key1); if(temp->key2!=INT_MAX) printf("%d ", temp->key2); if(temp->left) queue_insert(&front, &rear, temp->left); if(temp->middle) queue_insert(&front, &rear, temp->middle); if(temp->right) queue_insert(&front, &rear, temp->right); } else break; // case : temp == NULL } printf("\n"); } /*=====================================================================================*/ /********************************* stack_push() FUNCTION *******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> STACKÀÇ PUSH ¿¬»êÀ» ¼öÇàÇÏ´Â ÇÔ¼ö(¹æ¹®ÇÑ ³ëµåÀÇ ÁÖ¼Ò ÀúÀå) */ /*>>> CALL FUNCTION >>> NONE */ void stack_push(tree_ptr ads){ /* local variable declaration */ stk_ptr temp=(stk_ptr)malloc(sizeof(stack)); // dynamic allocation if(!temp){ // case : failed allocation (error message print & exit) printf("\n MEMORY IS FULL!!!\n"); exit(1); } temp->ads = ads; // address : save temp->link = stk_top; // link : save stk_top = temp; // top : re-adjustment } /*=====================================================================================*/ /********************************** stack_pop() FUNCTION *******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> STACKÀÇ POP ¿¬»êÀ» ¼öÇàÇÏ´Â ÇÔ¼ö(³ëµåÀÇ ÁÖ¼Ò ¸®ÅÏ) */ /*>>> CALL FUNCTION >>> NONE */ tree_ptr stack_pop(){ /* local variable declaration */ stk_ptr temp = stk_top; // address assignment tree_ptr item; if(!temp){ // case : stack is empty (error message print & exit) printf("\n THE STACK IS EMPTY\n\a"); exit(1); } item = temp->ads; // address : save stk_top = temp->link; // link : save free(temp); return item; } /*=====================================================================================*/ /******************************** queue_insert() FUNCTION ******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> QUEUEÀÇ INSERTION ¿¬»êÀ» ¼öÇàÇÏ´Â ÇÔ¼ö(³ëµåÀÇ ÁÖ¼Ò ÀúÀå) */ /*>>> CALL FUNCTION >>> NONE */ void queue_insert(que_ptr *front, que_ptr *rear, tree_ptr ads){ /* local variable declaration */ que_ptr temp = (que_ptr)malloc(sizeof(queue)); // dynamic allocation if(!temp){ // case : failed allocation (error message print & exit) printf("\n MEMORY IS FULL!!!\n"); exit(1); } temp->ads = ads; // address : save temp->link = NULL; // link : save if(*front) (*rear)->link = temp; else (*front) = temp; (*rear) = temp; } /*=====================================================================================*/ /******************************** queue_delete() FUNCTION ******************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> QUEUEÀÇ DELETION ¿¬»êÀ» ¼öÇàÇÏ´Â ÇÔ¼ö(³ëµåÀÇ ÁÖ¼Ò ¸®ÅÏ) */ /*>>> CALL FUNCTION >>> NONE */ tree_ptr queue_delete(que_ptr *front){ /* local variable declaration */ que_ptr temp = (*front); // address assignment tree_ptr item; if(!temp) return 0; item = temp->ads; // address : save (*front) = temp->link; // link : save free(temp); return item; } /*=====================================================================================*/ /*********************************** delay() FUNCTION **********************************/ /*=====================================================================================*/ /*>>> FUNCTION >>> Áö¿¬½Ã°£À» ÁÖ´Â ÇÔ¼ö */ /*>>> CALL FUNCTION >>> NONE */ void delay(clock_t sleep){ clock_t cur = clock(), el; for(;;){ /* ¹«ÇÑ·çÇÁ¸¦ µ¹¸°´Ù. */ el = clock(); /* ÇöÀç±îÁö ÇÁ·Î±×·¥ÀÌ ½ÇÇàµÈ TICK */ if((el - cur) > sleep) break ; } } ///////////////////////////////////////////////////////////////////////////////////////// /************************************** pRoGrAm eNd ************************************/ /////////////////////////////////////////////////////////////////////////////////////////