Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Õ»µÄCʵÏÖ(stack)

rows="2" cols="20" id="ctl00_ctl00_cphContent_cphDoc_EntryEditor1_richTextEditor" class="mceEditor" style="height:450px;width:100%;">
Õ»ÊÇÊý¾Ý½á¹¹ÖÐ×î»ù´¡Ò²ÊÇ×î¾­µäµÄÊý¾Ý½á¹¹£¬ÎÞÂÛÔÚÓ¦Óû¹ÊDzÙ×÷ϵͳÖоù¿ÉÒÔ¿´µ½ÆäÉíÓ°¡£Õ»ÊÇÒ»ÖÖÌØÊâµÄ
ÏßÐÔ±í£¬¼´ÏÞÖÆÔÚ±íµÄÒ»¶Ë½øÐвåÈ롢ɾ³ýÔËË㡣ͨ³£²åÈ롢ɾ³ýµÄÒ»¶Ë³ÆΪջ¶¥£¬ÁíÒ»¶Ë³ÆΪջµ×£¬µ±Õ»ÖÐû
ÓÐÊý¾Ýʱ³ÆΪ¿ÕÕ»¡£
Õ»ÖÐÊý¾ÝµÄ²åÈëºÍɾ³ýÖ»ÔÚÕ»¶¥½øÐУ¬ËùÒÔÕ»ÖеÄÊý¾Ý×ÜÊǺó½øÏȳö(LIFO)¡£
Õ»ÉÏ»ù±¾µÄÔËËãÓÐÎåÖÖ£º
* SETNULL(s) ÖÃÕ»sΪ¿ÕÕ»¡£
* EMPTY(s)   ÅжÏÕ»sÊÇ·ñΪ¿Õ¡£
* PUSH(s,x)  ÍùÕ»sѹÈëÊý¾Ýx¡£
* POP(s)     ÈôÕ»s²»Îª¿Õ£¬Ôòµ¯³öÕ»¶¥Êý¾Ý¡£
* TOP(s)     ÈôÕ»s²»Îª¿Õ£¬È¡Õ»¶¥Êý¾Ý¡£
ÏÂÃ棬¸ø³öÕ»µÄ×î»ù±¾µÄʵÏÖ´úÂë:
#include <assert.h>
#define STACK_SIZE (1 << 6)
static stack_t stack[STACK_SIZE];
static int top = -1;
static int stack_full(void)
{
return (top == STACK_SIZE - 1);
}
static int stack_empty(void)
{
return (top == -1);
}
void stack_push(stack_t val)
{
assert(!stack_full());
stack[++top] = val;
}
stack_t stack_pop(void)
{
assert(!stack_empty());
--top;
return stack[top + 1];
}
stack_t stack_top(void)
{
assert(!stack_empty());
return stack[top];
}
 
´ÓÉÏÃæµÄʵÏÖ´úÂë¿ÉÒÔ¿´³ö£¬ÊµÏÖÕ»µÄ»ù±¾²Ù×÷µÄ´úÂëÊǷdz£¼òµ¥µÄ£¬²»¹ý¶þÈýÊ®ÐеĴúÂëÁ¿¡£Èç¹ûÔÚʵ¼ÊµÄ´ú
Â뿪·¢ÖУ¬¸ù¾ÝÓ¦ÓõÄÌض¨Êý¾ÝÀàÐÍʵÏÖÉÏÊö¼¸¸ö²Ù×÷½Ó¿ÚÒ²ÊǺÜÈÝÒ׵ģ¬µ«´æÔÚ¼¸¸öÃ÷ÏÔµÄȱÏÝ:
* ´úÂë²»¾ß±¸¸´ÓÃÐÔ¡£
* ²ÉÓþ²Ì¬Êý×é´æ´¢£¬Õ»¿Õ¼äÐèÔÚ±àÒëÇ°È·¶¨¡£
* ²»Ö§³Ö´æ´¢¶àÖÖÊý¾ÝÀàÐÍ£¬ÐèÒªÐÞ¸Ästack_t¶¨Òå¡£
Ϊ´Ë£¬ÎÒÃÇÖØÐÂʵÏÖÁËÈçϵÄÒ»Ì׽ṹ£¬À´Âú×ãÉÏÃæµÄÕâЩ¸´ÓÃÐÔÌØÕ÷ÐèÇ󣬴úÂëÈçÏÂ:
#include <stdlib.h>
#include <string.h>
#include <assert.h>
struct _stack {
int top;
size_t len;
size_t size;
char *base;
};
typedef unsigned int hdl;
typedef struct _stack stack;
hdl stack_create(size_t size, size_t len)
{
stack *vp = (stack*)malloc(sizeof(stack));
if (vp == NULL) {
return 0;
}
assert(size > 0 && len > 0);
vp->base = (char*)malloc(size *


Ïà¹ØÎĵµ£º

CÓïÑÔº¯Êý£¨Ò»£©


ÔÚÇ°ÃæÒѾ­½éÉܹý£¬£ÃÔ´³ÌÐòÊÇÓɺ¯Êý×é³ÉµÄ¡£ËäÈ»ÔÚÇ°Ãæ¸÷ÕµijÌÐòÖдó¶¼Ö»ÓÐÒ»¸öÖ÷º¯Êýmain()£¬µ«ÊµÓóÌÐòÍùÍùÓɶà¸öº¯Êý×é³É¡£º¯ÊýÊÇ£ÃÔ´³ÌÐòµÄ»ù±¾Ä£¿é£¬Í¨¹ý¶Ôº¯ÊýÄ£¿éµÄµ÷ÓÃʵÏÖÌض¨µÄ¹¦ÄÜ¡££ÃÓïÑÔÖеĺ¯ÊýÏ൱ÓÚÆäËü¸ß¼¶ÓïÑÔµÄ×Ó³ÌÐò¡££ÃÓïÑÔ²»½öÌṩÁ˼«Îª·á¸»µÄ¿âº¯Êý(ÈçTurbo C£¬MS C¶¼ÌṩÁËÈý°Ù¶à¸ö¿âº¯Êý)£¬» ......

CÓïÑÔÖ¸Õ루¶þ£©


Ö¸ÕëÊÇ£ÃÓïÑÔÖй㷺ʹÓõÄÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÔËÓÃÖ¸Õë±à³ÌÊÇ£ÃÓïÑÔ×îÖ÷ÒªµÄ·ç¸ñÖ®Ò»¡£ÀûÓÃÖ¸Õë±äÁ¿¿ÉÒÔ±íʾ¸÷ÖÖÊý¾Ý½á¹¹£»Äܷܺ½±ãµØʹÓÃÊý×éºÍ×Ö·û´®£»²¢ÄÜÏó»ã±àÓïÑÔÒ»Ñù´¦ÀíÄÚ´æµØÖ·£¬´Ó¶ø±à³ö¾«Á·¶ø¸ßЧµÄ³ÌÐò¡£Ö¸Õ뼫´óµØ·á¸»ÁË£ÃÓïÑԵŦÄÜ¡£Ñ§Ï°Ö¸ÕëÊÇѧϰ£ÃÓïÑÔÖÐ×îÖØÒªµÄÒ»»·£¬ÄÜ·ñÕýÈ·Àí½âºÍʹÓÃÖ¸ÕëÊÇÎÒÃÇÊÇ·ñÕÆÎÕ ......

CÓïÑÔλÔËËã

Ç°Ãæ½éÉܵĸ÷ÖÖÔËË㶼ÊÇÒÔ×Ö½Ú×÷Ϊ×î»ù±¾Î»½øÐеġ£ µ«Ôںܶàϵͳ³ÌÐòÖг£ÒªÇóÔÚλ(bit)Ò»¼¶½øÐÐÔËËã»ò´¦Àí¡££ÃÓïÑÔÌṩÁËλÔËËãµÄ¹¦ÄÜ£¬ÕâʹµÃ£ÃÓïÑÔÒ²ÄÜÏñ»ã±àÓïÑÔÒ»ÑùÓÃÀ´±àдϵͳ³ÌÐò¡£
12.1 λÔËËã·û£ÃÓïÑÔÌṩÁËÁùÖÖλÔËËã·û£º
    &          °´ ......

ΪʲôѡÔñCÓïÑÔ

ΪʲôCÓïÑÔÒÀÈ»Èç´ËÁ÷ÐУ¿ÀúÊ·ÉÏ£¬ÓÉÓÚÖÖÖÖÔ­Òò£¬Òµ½çÑ¡ÔñÁËC£¬ÆäÖÐ×îÖ÷ÒªµÄÔ­Òò¾ÍÔÚÓÚËüµÄЧÂÊ¡£ÓÅÐãµÄC³ÌÐòµÄЧÂʼ¸ºõºÍ»ã
±àÓïÑÔ³ÌÐòÒ»Ñù¸ß£¬µ«C³ÌÐòÃ÷ÏԱȻã±àÓïÑÔ³ÌÐò¸üÒ×ÓÚ¿ª·¢¡£ºÍÐí¶àÆäËûÓïÑÔÏà±È£¬C¸øÓè³ÌÐòÔ±¸ü¶àµÄ¿ØÖÆȨ£¬Èç¿ØÖÆÊý¾ÝµÄ´æ´¢Î»Öúͳõʼ»¯¹ý³ÌµÈ¡£Cȱ·¦“°²È«Íø”ÌØÐÔ£¬ÕâËäÓÐÖúÓÚÌá¸ß ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ