In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, Xiaobian will bring you about the use of stacks in Java data structures. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
Stack is a special first-in-last-out linear table, allowing only insertion and deletion at the end of the table. Two ways to implement stack will be introduced later, which are array-based implementation and link-based implementation.
class Mystack{public: Mystack() {} virtual void push(int &x) = 0; virtual bool pop(int &x) = 0; virtual bool Top(int &x) const = 0; virtual bool IsEmpty()const = 0; virtual bool IsFull()const = 0; virtual int getSize()const = 0;}; Sequential Stack----------Use arrays to represent stack space
Definition:
#pragma once#include "Mystack.h"#include #include using namespace std;const int stackIncreament = 20;class SeqStack : public Mystack{public: SeqStack(int sz = 50); //Create an empty stack ~SeqStack() { delete[]elements; } //destructor //overflow program processing if stack is full, otherwise insert x void push(int &x); //If the stack is empty, return FALSE, otherwise use x to pass the value at the top of the stack, top-1 bool pop(int &x); //returns FALSE if stack is empty, otherwise uses x to pass stack top value bool Top(int &x); //determine whether the stack is empty bool IsEmpty()const { return (top == -1) ? true : false; } //determine whether the stack is full bool IsFull()const { return (top == maxSize - 1) ? true : false; } //Get the current stack size int getSize()const { return top + 1; } //Leave the stack empty void MakeEmpty() { top = -1; } //overload operation
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.