¶ÑÕ»µÄ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
& ......
Ò»¡¢»ù±¾ÖªÊ¶
Ö¸ÕëºÍÒýÓõÄÉùÃ÷·½Ê½£º
ÉùÃ÷Ö¸Õ룺char* pc;
ÉùÃ÷ÒýÓãºchar& rc = 0;
ËüÃǵÄÇø±ð£º
¢Ù´ÓÏÖÏóÉÏ¿´£¬Ö¸ÕëÔÚÔËÐÐʱ¿ÉÒԸıäÆäËùÖ¸ÏòµÄÖµ£¬¶øÒýÓÃÒ»µ©ºÍij¸ö¶ÔÏó°ó¶¨ºó¾Í²»Ôٸı䡣Õâ¾ä»°¿ÉÒÔÀí½âΪ£ºÖ¸Õë¿ÉÒÔ±»ÖØÐ¸³ÖµÒÔÖ¸ÏòÁíÒ»¸ö²»Í¬µÄ¶ÔÏó¡£µ«ÊÇÒýÓÃÔò×ÜÊÇÖ¸ÏòÔÚ³õʼ»¯Ê±±»Ö¸¶¨µÄ¶Ô ......
gcc£¬gdbµÄʹÓÃ
×÷Õߣºzccst
ÉÏÖÜÎåÔÚͼÊé¹Ý½èÁËÒ»±¾¡¶LinuxÈí¼þ¹¤³Ìʦ£¨CÓïÑÔ£©ÊµÓý̡̳·£¬ÈÃÎÒÊÕ»ñÁ¼¶à¡£²»½ö½öÊÇÊéÖеÄ֪ʶ£¬»¹ÓжÔ֪ʶÌåϵºÍ¼Ü¹¹ÈÏʶµÄÉîÈë¡£
LinuxÏÂC¿ª·¢£º
1£¬gcc,gdbµÄʹÓá£
2£¬MakefileÎļþµÄ±àд¡£
3£¬ÏµÍ³º¯ÊýµÄʹÓÃ
4£¬Îļþ²Ù×÷
5£¬´®ÐÐͨÐÅ
6£¬½ø³Ì¿ØÖÆ
7£¬½ø³Ì¼ ......
In C programming language, the observer design pattern is implemented with function pointer (aka callback function). But in Qt library, it introduces signal and slot. How to link a callback function from the C callback function to the C++ siganl and slot is a problem I encounter. Call back function ......
Java¿çƽ̨µÄÌØÐÔʹJavaÔ½À´Ô½ÊÜ¿ª·¢ÈËÔ±µÄ»¶Ó£¬µ«Ò²ÍùÍù»áÌýµ½²»Éٵı§Ô¹£ºÓÃJava¿ª·¢µÄͼÐÎÓû§´°¿Ú½çÃæÃ¿´ÎÔÚÆô¶¯µÄʱºò¶¼»áÌø³öÒ»¸ö¿ØÖÆÌ¨´°¿Ú£¬Õâ¸ö¿ØÖÆÌ¨´°¿ÚÈñ¾À´·Ç³£°ôµÄ½çÃæÊ§É«²»ÉÙ¡£ÔõôÄܹ»ÈÃͨ¹ýJava¿ª·¢µÄGUI³ÌÐò²»µ¯³öJavaµÄ¿ØÖÆÌ¨´°¿ÚÄØ£¿ÆäʵÏÖÔںܶàÁ÷ÐеĿª·¢»·¾³ÀýÈçJBuilder¡¢Eclipse¶¼ÊÇʹÓô¿Java ......