#include #include "version.h" #include "link.h" #include "buf.h" /* * ¦ÐÑ * top ÐþÓÀÃóÓáõÓñ * ߯Ի°À */ BOOL Nodeappendtail( Node** top , Node* add ) { Node* c; /*»ï¡õÃóåÃ*/ Node* next; /*Þ¥ØÆÈÊ×ÛÔÂÓáõÓñåÃ*/ /*ÐþÓÀÃó»¥NULL¾®Éýµ¤¾®¼°ÃñÄáÓÀÛÍ*/ if( *top == NULL ){ *top = allocateMemory( sizeof( Node ) ); if( *top== NULL ) return FALSE; (*top)->next = NULL; /*Á¸Îå·´ ÖÐ*/ (*top)->size = add->size; /*Ó®½ñ¼°â綰*/ (*top)->val = add->val; /*ºÌÄ̼þÕý¡õ¼°Îìñâ¡õ*/ return TRUE; } for( c = *top ; c->next ; c = c->next ); /* c¼°ÞË Ã«ÄÚÈÕÔÊ */ next = allocateMemory( sizeof(Node) ); if( next == NULL )return FALSE; c->next = next; /* next±å°ÀëɬÀÃÔÊÔ */ next->next = NULL; /*Á¸Îå·´ ÖÐ*/ next->val = add->val; /*ºÌÄ̼þÕý¡õ¼°Îìñâ¡õ*/ next->size = add->size; /*Ó®½ñ¼°â綰*/ return TRUE; } /* * Øø¼þÛͼ°ó¡±å¹´ØêÔ * ¦ÐÑ * top ÐþÓÀÃóÓáõÓñ * ߯Ի°À */ BOOL Nodeappendhead( Node** nowtop , Node* add ) { Node* newtop; /*Þ¥ØÆÖÐÛÆ åÃ*/ /*ÐþÓÀÃó»¥NULL¾®Éýµ¤¾®¼°ÃñÄáÓÀÛÍ*/ if( *nowtop == NULL ){ *nowtop = allocateMemory( sizeof( Node ) ); if( *nowtop == NULL ) return FALSE; (*nowtop)->next = NULL; /*Á¸Îå·´ ÖÐ*/ (*nowtop)->size = add->size; /*Ó®½ñ¼°â綰*/ (*nowtop)->val = add->val; /*ºÌÄ̼þÕý¡õ¼°Îìñâ¡õ*/ return TRUE; } /* * Þ¥ØÆÖÐÓáõÓñëÓò¹´×ÛÔ */ newtop = allocateMemory( sizeof(Node) ); newtop->next = *nowtop; newtop->val = add->val; newtop->size = add->size; *nowtop = newtop; return TRUE; } /* * ¦ÐÑ * ret äúÔ»ÂÖÖÐÐ×ÓáõÓñ¼°Îìñâ¡õ * ߯Ի°À */ BOOL Noderemovehead( Node** top , Node* ret) { Node* newtop; /*Þ¥ØÆÈÊÛÆ ±åئÔÂÓáõÓñ*/ if( *top == NULL )return FALSE; ret->val = (*top)->val; ret->size = (*top)->size; newtop = (*top)->next; freeMemory( *top ); *top = newtop; return TRUE; } /* * ¦ÐÑ * ret äúÔ»ÂÖÖÐÐ×ÓáõÓñ¼°Îìñâ¡õ * ߯Ի°À */ BOOL Noderemovetail( Node** top , Node* ret) { Node* c; /*»ï¡õÃóåÃ*/ Node* c1; /*»ï¡õÃóåà Öй´Æ¥ÊÖ c->nextë϶ÔÊ*/ if( *top == NULL )return FALSE; c = *top; /*âÙÓå°ÀɬÀÃ*/ c1 = c->next; /*âÙÓå°ÀɬÀÃ*/ while(1){ if( c1->next == NULL ) /* * ³ð¼°ÁÝ÷§Æ¥ c1 * | * | next |---->+------+ * |------| | next |---->NULL * | | +------+ * +------+ | | * +------+ *ÎçئÔÈ»¯ÖÐÔ */ break; c=c->next; c1=c->next; } c->next = NULL; /*c1±åؤÐ×ÔÂÊÖ¼°Ã«´ÂÂÖÔÊÔ¼°Æ¥next·´NULLÎçÔÊÔÂ*/ /*Îìñâ¡õ*/ ret->val = c1->val; ret->size = c1->size; freeMemory( c1 ); return TRUE; }