Õ»µÄ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 *
Ïà¹ØÎĵµ£º
¡¾checkpass.c¡¿
#include <stdio.h>
#include <string.h>
int checkpass(void){
int x;
char a[9];
x = 0;
fprintf(stderr,"a at %p and\nx at %p\n", (void *)a, (void *)&x);
printf("Enter a short word: ");
&nbs ......
Ö¸ÕëÊÇ£ÃÓïÑÔÖй㷺ʹÓõÄÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÔËÓÃÖ¸Õë±à³ÌÊÇ£ÃÓïÑÔ×îÖ÷ÒªµÄ·ç¸ñÖ®Ò»¡£ÀûÓÃÖ¸Õë±äÁ¿¿ÉÒÔ±íʾ¸÷ÖÖÊý¾Ý½á¹¹£»Äܷܺ½±ãµØʹÓÃÊý×éºÍ×Ö·û´®£»²¢ÄÜÏó»ã±àÓïÑÔÒ»Ñù´¦ÀíÄÚ´æµØÖ·£¬´Ó¶ø±à³ö¾«Á·¶ø¸ßЧµÄ³ÌÐò¡£Ö¸Õ뼫´óµØ·á¸»ÁË£ÃÓïÑԵŦÄÜ¡£Ñ§Ï°Ö¸ÕëÊÇѧϰ£ÃÓïÑÔÖÐ×îÖØÒªµÄÒ»»·£¬ÄÜ·ñÕýÈ·Àí½âºÍʹÓÃÖ¸ÕëÊÇÎÒÃÇÊÇ·ñÕÆÎÕ ......
11.1 ¶¨ÒåÒ»¸ö½á¹¹µÄÒ»°ãÐÎʽ
ÔÚʵ¼ÊÎÊÌâÖУ¬Ò»×éÊý¾ÝÍùÍù¾ßÓв»Í¬µÄÊý¾ÝÀàÐÍ¡£ÀýÈ磬ÔÚѧÉúµÇ¼Ç±íÖУ¬ÐÕÃûӦΪ×Ö·ûÐÍ£»Ñ§ºÅ¿ÉΪÕûÐÍ»ò×Ö·ûÐÍ£»ÄêÁäӦΪÕûÐÍ£»ÐÔ±ðӦΪ×Ö·ûÐÍ£»³É¼¨¿ÉΪÕûÐÍ»òʵÐÍ¡£ ÏÔÈ»²»ÄÜÓÃÒ»¸öÊý×éÀ´´æ·ÅÕâÒ»×éÊý¾Ý¡£ÒòΪÊý×éÖи÷ÔªËصÄÀàÐͺͳ¤¶È¶¼±ØÐëÒ»Ö£¬ÒÔ±ãÓÚ±àÒëϵͳ´¦Àí¡ ......
ÎÒÊÇÒ»¸ö¼ÆËã»úרҵµÄ±¾¿ÆÉú£¬ÏÖÔÚÎÒÃǸոÕѧÍêÁËÊý¾Ý½á¹¹¡£¾Ý˵Êý¾Ý½á¹¹¶ÔÓÚÎÒÃDZà³ÌºÜÖØÒª£¬¿ÉÊÇÎÒÏÖÔÚ²»ÖªÔõô°ÑÊý¾Ý½á¹¹ºÍCÓïÑÔ½áºÏÆðÀ´£¬ÒÔ±ã¸üºÃµÄ½øÐÐcÓïÑÔ±à³Ì¡£ÓÐÄÄλ¸ßÊÖÖ¸µãÒ»¶þ£¬ÔÚÏ¸м¤²»¾¡£¡
......