对代码的理解 [英] understanding of code

查看:68
本文介绍了对代码的理解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Turbo并想根据该版本了解代码

即时通讯处理的代码太多了,因为代码样式不同
从turbo c borland到visual c和dev c的各个方面.

我想实现执行所有基本操作的堆栈类

我知道有6种基本操作可以对stack进行pop pop初始化.在每次push和pop之前检查堆栈是否已满和空.

指针数组将帮助用户在程序执行期间告知其容量,但静态数组是固定大小的方法.

私有成员是int top和int * array.

我想知道该程序中任何地方的主要部分和其他部分的可访问性范围都已实现

我在构造函数方面遇到了麻烦,最初的阶段是什么

stack();

在构造函数中的定义top等于-1或0(如果从零开始将首先从索引1存储元素,则从0开始存储)

它将构造一个堆栈对象,但其中
如果在main中,那么它将如何

我想知道在Turbo C中我应该使用什么头文件

希望得到良好的答复.

im using turbo and want to know code according to that version

im dealing with stack that is too much cofusing because code styles are different
in every ide from turbo c borland to visual c and dev c.

i want to implement stack class that perform all basic operations

i know there are six basic operations push pop intialization of stack.check for stack full and empty before every push and pop.

pointer array will help to tell its capacity by user during program execuation but static array is fixed size method.

private memebers are int top and int *array.

i want to know there accessibility scope realted to main and other parts where ever in the program

i am trouble with constructor what it will be at intial stage

stack();

in constructor defination top is equal to -1 or 0 if from zero first pushed element will stored from index 1 otherwise from 0)

it will construct a stack object but where
in main if in main then how it will be

i want to know in turbo c what header files i should use

hoping for good reply.

推荐答案

如果您所做的只是实现基本堆栈,那么您不需要任何复杂的东西,并且您不太可能会特别需要任何头文件.

要模拟堆栈,您需要一个内存区域:一个数组或堆上的一块内存-我自己去堆.
假设您正在使用堆(如果使用数组,则对于指针读取索引),您将需要一个基本指针来显示它的开始位置,一个当前指针来显示它的结束位置,以及一个大小值来显示如何很大.

初始化:
分配内存,将两个指针设置为开始,设置大小.
CheckEmpty:
电流等于基数吗?
检查完整:
电流是否大于或等于基数+大小?
推送:
如果未满,请将值放在当前"位置,将当前"增加值的大小.
流行音乐:
如果不为空,请按值的大小减小当前",然后从当前"位置获取值.

完成!
If all you are doing is implementing a basic stack, then you shouldn''t need anything complex, and it is unlikely that you would need any header files in particular.

To emulate a stack, you need an area of memory: either an array, or a chunk of memory on the heap - I would go with the heap myself.
Assuming you are using the heap (if you use an array, then for pointer read index) you will need a base pointer to show you where it starts, a current pointer to show you where it ends, and a size value to show you how big it is.

Init:
Allocate the memory, set the two pointers to the start, set the size.
CheckEmpty:
Is Current equal to Base?
Check full:
Is Current greater than or equal to Base + Size?
Push:
If not full, put the value to the Current location, increase Current by size of value.
Pop:
If not empty, decrease Current by size of value, get value from Current location.

Done!


在这里您可以找到C++实现:堆栈实现作为类" [ ^ ] .
由于堆栈是一个通用概念,因此您应该能够使用所选的编译器毫无问题地实现.
Here you may find a C++ implementation: "Stack implementation as a class"[^].
Since stack is a general concept, you should be able to implement without problems with the compiler of your choice.


这篇关于对代码的理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆