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

cºÍc++ÏÂÓÃջʵÏÖÊýµÄ½øÖÆת»»

1. CµÄʵÏÖ
//stack.h
#ifndef STACK_H
#define STACK_H
#define STACK_CAPACITY 20//maximum size of stack
typedef int stackEle;
typedef struct
{
stackEle myArray[ STACK_CAPACITY ];
int myTop;
}stack;
//construct(initialize) an empty stack
stack *stack_init(void);
//return 1 if stack is empty and 0 otherwise
int empty(stack *);
//retrieve top element of the stack
stackEle top(stack* );
//add an element at the top of the stack
void push(stack*,stackEle);
//remove the top element of the stack
void pop(stack* );
#endif
//stack.c
#include <stdio.h>
#include "stack.h"
#include <assert.h>
#include <stdlib.h>
//construct (initialize) an empty stack
stack* stack_init(void)
{
stack* s = (stack*)malloc(sizeof(stack));
assert(s);
s->myTop = -1;//stack is empty
return s;
}
//return 1 if stack is empty and 0 otherwise
int empty(stack *s)
{
assert(s);
if(0 > s->myTop)
return 1;
else
return 0;

}
//retrieve top element of the stack
stackEle top(stack* s)
{
assert(s);
if(0 > s->myTop)
{
printf("Error:stack is empty--no value can be reported\n");
exit(1);
}
return s->myArray[s->myTop];
}
//add an element at the top of the stack
void push(stack* s,stackEle val)
{
assert(s);
s->myTop++;
if(STACK_CAPACITY < s->myTop)//check if overflow
{
printf("Error:stack is full--can't add new value\n");
exit(1);
}
s->myArray[s->myTop] = val;
}
//remove the top element of the stack
void pop(stack* s)
{
assert(s);
if(0 > s->myTop)//check if underflow
{
printf("Error:stack is empty--can't remove a value\n");
exit(1);
}
printf("%d ",s->myArray[s->myTop--]);
}
//do base-10 to base-2 transformation by array-based stack
int main()
{
stack *mystack = stack_init();
int a = 255,b,base = 2;
do
{
b = a % base;
push(mystack,b);
a = a / base;
} while(a != 0);

while(!empty(mystack))
pop(mystack);


Ïà¹ØÎĵµ£º

dbca³ö´íC [libnnz11.so+0x3c3a8]

2010Äê05ÔÂ1ºÅ  | 
23:15·ÖÀࣺ¹ÜÀíά»¤
, Õï¶Ï°¸Àý
  |  ±à¼­
  |  ±êÇ©£º11g
¡¢dbca
¡¢netca
  |  13
views
±¾Îijö×Ô “inthirties£¨ÄÐ
ÈËÈýÊ®£©
”²©¿Í£¬×ªÔØÇëÎñ±Ø×¢Ã÷×÷Õߺͱ£Áô³ö´¦¡£
¿Í»§×°ºÃÁËOracle£¬°²×°³É¹¦ÁË£ ......

LINUX C ¶¨Ê±Æ÷

¡¾ÊµÏÖ¹¦ÄÜ¡¿£ºLinuxϵÄC±à³Ì£º±àдһ¸ö³ÌÐò£¨¿â£©£¬ÊµÏÖ¶¨Ê±Æ÷£¨¼ÆʱÆ÷£©µÄ¹¦ÄÜ£¬ËüÄÜΪÓû§ÌṩÔÚͬһ½ø³ÌÖжà´ÎʹÓõĶ¨Ê±Æ÷¡£ÕâÀïÒªÇóÓÃÐźÅÀ´ÊµÏÖ¡£
¡¾½âÌâ˼·¡¿£º±àдһ¸ö½á¹¹ÌåTimer´ú±íÒ»¸ö¼ÆʱÆ÷£¬È»ºóÔÙ¶¨ÒåTimerÀàÐ͵ÄÊý×émyTimer[N]£¬ÓÃÀ´±£´æÎÒÃÇÉèÖõĶ¨Ê±Æ÷£»ÔÙ¶¨Ò庯ÊýsetTimer£¨£©Éú³É¼ÆʱÆ÷£¬²¢½«Éú³É ......

C preprocessor

Ò»Ö±¾õµÃCÓïÑÔµÄÔ¤´¦Àí
Æ÷ÊǸöÃÀÃî¶øÉñÆæµÄ¹¤¾ß£¬ÒÔºó»á½Ðø°Ñ×Ô¼ºÑ§µ½µÄ¹ØÓÚËüµÄÐÂ֪ʶ×ܽá³öÀ´¡£To be continued aways...
Ò»¡¢ #defineÌæ»»
£¨Pointer ON C
, Ch14.2.2£©
³ÌÐòÖÐÀ©Õ¹#define¶¨Òå·ûºÅºÍºêʱ£¬Éæ¼°Èçϼ¸¸ö²½Ö裺
(1) ÔÚµ÷Óúêʱ£¬Ê×ÏȶԲÎÊý½øÐмì²é£¬¿´¿´ÊÇ·ñ°üº¬ÁËÈκÎÓÉ#define ¶¨ÒåµÄ·ûºÅ£¬Èç¹ ......

ÓÅ»¯C´úÂë³£Óõļ¸ÕÐ

ÓÅ»¯C´úÂë³£Óõļ¸ÕÐ
ÔÚÐÔÄÜÓÅ»¯·½ÃæÓÀԶעÒâ80-20Ô­Ôò£¬¼´20%µÄ³ÌÐòÏûºÄÁË80%µÄÔËÐÐʱ¼ä£¬Òò¶øÎÒÃÇÒª¸Ä½øЧÂÊ£¬×îÖ÷ÒªÊÇ¿¼ÂǸĽøÄÇ20%µÄ´úÂë¡£²»ÒªÓÅ»¯³ÌÐòÖпªÏú²»´óµÄÄÇ80%£¬ÕâÊÇÀͶøÎÞ¹¦µÄ¡£
µÚÒ»ÕУºÒԿռ任ʱ¼ä
¼ÆËã»ú³ÌÐòÖÐ×î´óµÄì¶ÜÊÇ¿Õ¼äºÍʱ¼äµÄì¶Ü£¬ÄÇô£¬´ÓÕâ¸ö½Ç¶È³ö·¢ÄæÏò˼άÀ´¿¼ÂdzÌÐòµÄЧÂÊÎÊÌ⣬ÎÒ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ