Stack (v0.1)

zhaozj2021-02-11  202

Undecided

1 package org.spring.ds.aRraystack;

2

3 / **

4 * Created by Intellij Idea.

5 * User: chunyang

6 * Date: 2003-6-20

7 * Time: 15:35:22

8 * develop with pleasure !.

9 * Array Based Stack Class

10 * /

11 public class myarraystack {

12 // Array Holding Stack Objects

13 protected object [] array;

14 // Index for Top Object

15 protected int top;

16

17 public myaarraystack (int size) {

18 array = new object [size];

19 TOP = -1;

20}

twenty one

22 public boolean iSempty () {

23 returnit == -1;

twenty four }

25 / **

26 * Push Object Onto Stack

27 * @Param O

28 * /

29 Public Void Push (Object Obj) {

30 IF (TOP 1

31 Array [ TOP] = OBJ;

32}

33

34 / **

35 * POP Object from top of stack

36 * @return

37 * /

38 Public Object Pop () {

39 IF (ISEMPTY ())

40 Return NULL;

41 Return Array [TOP -];

42}

43

44

45 / **

46 * Remove All Objects from stack

47 * /

48 public void clear () {

49 TOP = -1;

50}

51} // Class MyArrayStack

52

转载请注明原文地址:https://www.9cbs.com/read-4349.html

New Post(0)