473,397 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How do I reinitalize index [top] of both of these restricted structures to 0?

74 64KB
Hello Everyone,

I have question: how do I reinitalize index [top] of both of these restricted structures to 0?

Here is the Stack Push Algorithm:

Expand|Select|Wrap|Line Numbers
  1.        if (top == 0) 
  2.           return false; // ** overflow error 
  3.        else 
  4.        { 
  5.               top = top + 1; data[top] = newNode.deepCopy(); 
  6.               return true;  // push operation successful 
  7.        }
  8.  
  9.  
Here is the stack Pop algorithm:

Expand|Select|Wrap|Line Numbers
  1. if(top == -1) return null;  // ** underflow error ** else {  topLocation = top; top = top - 1; return data[topLocation]; // returns a shallow copy } 
Sep 28 '17 #1
1 1706
chaarmann
785 Expert 512MB
just setting top=0 ? No? So describe what you want in more detail. I see only array "data" aut not array "index" in your code.
And data = new int[data.length] will just clear your array. (or whatever type you have in your array, I just assumed "int")
Sep 29 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Peter Olcott | last post by:
I want to be able to efficiently build data structures at run-time. These data structures need to be accessed with minimal time. The only a few ways that come immediately to mind would be some...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
24
by: Henrik Steffen | last post by:
hello all, on my master-db-server i'm running postgres 7.4.1, and I have got two slave-servers running postgres 7.4.2 running the following query on the master-server (7.4.1) delivers: ...
7
by: Dave Hammond | last post by:
Hi All, I'd like to have indexed search capability on column A, column B, or columns (A,B) for a given table. According to the MySQL manual, a multi-column index of (A,B) will provide "leftmost...
5
by: utab | last post by:
Dear all, I was reading something on data structures on c++ and in that chapter it was telling that the same components will be more efficiently substituted with the STL ones. So can somebody...
3
by: Newbie | last post by:
I have two different levels of people who want to see my production report. We get orders which each call for one of five products. One level wants to see a spreadsheet type report with six...
2
Fary4u
by: Fary4u | last post by:
Hi is there any way i can show the picture coordinates + display some additional text on the upper layer? like image is on the back & top is the word information. ...
8
by: Bob Altman | last post by:
Hi all, I have a structure that includes a constructor. I want to add a bunch of these structures to an STL map (whose index is an int). If I define the map like this: map<int,...
0
by: Serge Rielau | last post by:
DA Morgan wrote: I do not know SQL Server's Cluster Index, can't comment there. DB2 does not have an "index only table". There are two table types that have "some" overlap: * Range Clustered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.