易截截图软件、单文件、免安装、纯绿色、仅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);


相关文档:

打开IE说无法找到脚本文件【C:Progeam Files\*】

今天发现电脑出现莫名奇妙的问题,任务栏的图标都无法使用了。而且注册表也无法使用。
处理方法:
一、先解锁注册表。此步骤后可以正常访问修改注册表。
http://zhidao.baidu.com/question/8109053.html?fr=ala0
注册表被管理员停用,
1、新建一个文本文件,在其中输入以下内容。
[HKEY_CURRENT_USER/Software/Micro ......

Visual C++ C runtime库名称分析

单线程
Single-Threaded(static)                            libc.lib
Debug Single-Threaded(static)           & ......

LINUX C 定时器

【实现功能】:Linux下的C编程:编写一个程序(库),实现定时器(计时器)的功能,它能为用户提供在同一进程中多次使用的定时器。这里要求用信号来实现。
【解题思路】:编写一个结构体Timer代表一个计时器,然后再定义Timer类型的数组myTimer[N],用来保存我们设置的定时器;再定义函数setTimer()生成计时器,并将生成 ......

学生管理系统(c/cpp)

#include
using namespace std;
typedef struct lnode
{
    long sno;
    char name[20];
    struct lnode *next;
}LNode, *LinkList;
LinkList InitList()
{
    LinkList head;
    head = new LNode;
 &nb ......

C 编程最佳实践


简介
本文是为了满足开发人员的需要而写的。我们总结了一套指南,无论作为开发人员还是顾问,这些指南多年来一直都很好地指导着我们,我们把它们作为建议提供给您,希望对您的工作有所帮助。您也许不赞同其中的某些指南,但我们希望您会喜欢其中的一些并在您的编程或移植项目中使用它们。
风格与指南
使用一种使代码具 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号