¶ÑÕ»µÄC´úÂëʵÏÖ
2009-09-13 16:42:43
½ñÌìʵÏÖ¶ÑÕ»½á¹¹²¿·ÖµÄ´úÂ룬²¢ÓÃÒ»¼òµ¥³ÌÐò²âÊԳɹ¦¡£
stack.h:
#ifndef _STACK_H_
#define _STACK_H_
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#define STACK_INIT_SIZE 5
#define STACKINCREMENT 5
typedef int SElemType; //the elements type
typedef enum {
TRUE=0,
FALSE=-1
} Status;
typedef struct {
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status InitStack(SqStack *S);
Status DestoryStack(SqStack *S);
Status ClearStack(SqStack *S);
Status StackEmpty(SqStack S);
int LengthStack(SqStack S);
Status GetTop(SqStack S,SElemType *e);
Status Push(SqStack *S,SElemType e);
Status Pop(SqStack *S,SElemType *e);
Status StackTraverse(SqStack S);
#endif
stack.c
#include "Stack.h"
Status InitStack (SqStack *S)
{
if((S->base=(SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType)))==(SElemType*)NULL){
printf("init stack malloc error !\n");
return FALSE;
}
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
return TRUE;
}
Status DestoryStack(SqStack* S)
{
free(S->base);
S->base=S->top=(SElemType*)NULL;
S->stacksize=0;
return TRUE;
}
Status ClearStack(SqStack * S)
{
if(S->top <= S->base){
printf("not stack or empty stack !\n");
return FALSE;
}
S->top = S->base;
return FALSE;
}
Status StackEmpty(SqStack S)
{
if(S.top == S.base){
printf("empty stack checked!\n");
return TRUE;
}
else return FALSE;
}
int LengthStack(SqStack S)
{
return S.top-S.base;
}
Status GetTop(SqStack S, SElemType * e)
{
if(S.top==S.base){
printf("the stack is already empty !\n");
return FALSE;
}
*e=*(S.top-1);
return TRUE;
}
Status StackRealloc (SqStack *S, size_t size)
{
size_t offset = 0;
SElemType* temp = (SElemType *)NULL;
if((temp = (SElemType*)malloc(size))==(SElemType*)NULL){
printf("realloc address OX%d\n");
printf("realloc error!
Ïà¹ØÎĵµ£º
תÖÁhttp://www.pconline.com.cn/pcedu/empolder/gj/c/0503/566020.html
º¯Êý´æ·ÅÔÚÄÚ´æµÄ´úÂëÇøÓòÄÚ£¬ËüÃÇͬÑùÓеØÖ·£¬ÎÒÃÇÈçºÎÄÜ»ñµÃº¯ÊýµÄµØÖ·ÄØ£¿
¡¡¡¡Èç¹ûÎÒÃÇÓÐÒ»¸öint test(int a)µÄº¯Êý£¬ÄÇô£¬ËüµÄµØÖ·¾ÍÊǺ¯ÊýµÄÃû×Ö£¬ÕâÒ»µãÈçͬÊý×éÒ»Ñù£¬Êý×éµÄÃû×Ö¾ÍÊÇÊý×éµÄÆðʼµØÖ·¡£
¡¡¡¡¶¨ÒåÒ»¸öÖ¸Ïòº¯ÊýµÄÖ¸ÕëÓÃÈçÏ ......
×÷Õߣº
Ôøºê°²£¬»ªÇåÔ¶¼ûǶÈëʽѧԺ
¸ß¼¶½²Ê¦¡£
ÔËËã·ûsizeof¿ÉÒÔ¼ÆËã³ö¸ø¶¨ÀàÐ͵ĴóС£¬¶ÔÓÚ32λϵͳÀ´Ëµ£¬sizeof(char) = 1; sizeof(int) = 4¡£»ù±¾Êý¾ÝÀàÐ͵ĴóСºÜºÃ¼ÆË㣬ÎÒÃÇÀ´¿´Ò»ÏÂÈçºÎ¼ÆËã¹¹ÔìÊý¾ÝÀàÐ͵ĴóС¡£
CÓïÑÔÖеĹ¹ÔìÊý¾ÝÀàÐÍÓÐÈýÖÖ£ºÊý×é¡¢½á¹¹ÌåºÍ¹²ÓÃÌå¡£
Êý×éÊÇÏàͬÀàÐ͵ÄÔªËØµÄ¼¯ºÏ£¬Ö»Òª»á¼ÆËã ......
1.
¹ØÓÚchar* ºÍconst char*ÒÔ¼°char**ºÍconst char**·Ö±ð×÷Ϊʵ²ÎºÍÐβεÄÎÊÌâ
´«ÖµÊµ¼ÊÉÏÊÇÀàËÆÓÚ¸³ÖµµÄ¡£
Á½¸ö²Ù×÷Êý¶¼ÊÇÖ¸ÏòÏÞ¶¨·û»òÎÞÏÞ¶¨·ûµÄÏàÈÝÀàÐ͵ÄÖ¸Õ룬×ó±ßÖ¸ÕëËùÖ¸ÏòµÄÀàÐͱØÐë¾ßÓÐÓÒ±ßÖ¸ÕëËùÖ¸ÏòÀàÐ͵ÄÈ«²¿ÏÞ¶¨·û¡£ ......
´òÓ¡×Ô¼ºµÄÒ»¶ÎƯÁÁC³ÌÐò
#include <stdio.h>
int main()
{
char *p ="#include <stdio.h>%c int main(){char *p=%c%s%c; printf(p, 10, 34, p, 34);}";
printf(p, 10, 34, p, 34);
} ......
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå
¹ØÓÚº¯ÊýÖ¸ÕëÊý×éµÄ¶¨Òå·½·¨£¬ÓÐÁ½ÖÖ£ºÒ»ÖÖÊDZê×¼µÄ·½·¨£»Ò»ÖÖÊÇÃÉÆ·¨¡£
µÚÒ»ÖÖ£¬±ê×¼·½·¨£º
{
·ÖÎö£ºº¯ÊýÖ¸ÕëÊý×éÊÇÒ»¸öÆäÔªËØÊǺ¯ÊýÖ¸ÕëµÄÊý×é¡£ÄÇôҲ¾ÍÊÇ˵£¬´ËÊý¾Ý½á¹¹ÊÇÊÇÒ»¸öÊý×飬ÇÒÆäÔªËØÊÇÒ»¸öÖ¸Ïòº¯ÊýÈë¿ÚµØÖ·µÄÖ¸Õë¡£
¸ù¾Ý·ÖÎö£ºÊ×ÏÈ˵Ã÷ÊÇÒ»¸öÊý×飺Êý×éÃû[]
Æä´Î£¬ÒªËµÃ ......