¶ÑÕ»µÄ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!
Ïà¹ØÎĵµ£º
1¡¢ ¾³£¿´¼ûreturn EXIT_SUCCESS»òreturn EXIT_FAILURE£¬µ«¶¼²»ÖªÕâÁ½¸öÀ´×Ժ䦣¬ÏÖÔÚ²ÅÖªÔÀ´stdlib.h¶¨ÒåÁËEXIT_SUCCESSºÍEXIT_FAILURE·ûºÅ¡£
ÔÚstdlib.hÍ·ÎļþÀ
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
& ......
¡¡¡¡ÒýÑÔ
¡¡¡¡Ö¸ÕëÊÇC/C++ÓïÑÔµÄÌØÉ«£¬¶øÊý×éÃûÓëÖ¸ÕëÓÐÌ«¶àµÄÏàËÆ£¬ÉõÖÁºÜ¶àʱºò£¬Êý×éÃû¿ÉÒÔ×÷ΪָÕëʹÓá£ÓÚÊǺõ£¬ºÜ¶à³ÌÐòÉè¼ÆÕ߾ͱ»¸ãºýÍ¿ÁË¡£¶øÐí¶àµÄ´óѧÀÏʦ£¬ËûÃÇÔÚCÓïÑԵĽÌѧ¹ý³ÌÖÐÒ²´íÎóµÃ¸øѧÉú½²½â£º"Êý×éÃû¾ÍÊÇÖ¸Õë"¡£ºÜÐÒÔË£¬ÎҵĴóѧÀÏʦ¾ÍÊÇÆäÖÐÖ®Ò»¡£Ê±ÖÁ½ñÈÕ£¬ÎÒÈÕ¸´Ò»ÈյؽøÐÐ×ÅC/C++ÏîÄ¿µÄ¿ª·¢£¬¶øÉ ......
C/C++ÖеÄÈÕÆÚºÍʱ¼ä
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£º
UTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Ti ......
תÖÁhttp://www.pconline.com.cn/pcedu/empolder/gj/c/0503/566020.html
º¯Êý´æ·ÅÔÚÄÚ´æµÄ´úÂëÇøÓòÄÚ£¬ËüÃÇͬÑùÓеØÖ·£¬ÎÒÃÇÈçºÎÄÜ»ñµÃº¯ÊýµÄµØÖ·ÄØ£¿
¡¡¡¡Èç¹ûÎÒÃÇÓÐÒ»¸öint test(int a)µÄº¯Êý£¬ÄÇô£¬ËüµÄµØÖ·¾ÍÊǺ¯ÊýµÄÃû×Ö£¬ÕâÒ»µãÈçͬÊý×éÒ»Ñù£¬Êý×éµÄÃû×Ö¾ÍÊÇÊý×éµÄÆðʼµØÖ·¡£
¡¡¡¡¶¨ÒåÒ»¸öÖ¸Ïòº¯ÊýµÄÖ¸ÕëÓÃÈçÏ ......