Solved

Creating stacks

Posted on 2009-04-01
13
195 Views
Last Modified: 2012-05-06
hi everyone,

i might have a dumb question...  is it possible to create 3 stacks with similar but added stuff...
i am not looking for code but for some direction...

lets say i have a stack A that has things such as int a , int b.
now stack B would have int a and int b as well as int c..
stack C would have int a, int b, int c,int d...
the above is the simplified version...thanks
0
Comment
Question by:zizi21
  • 4
  • 3
  • 2
  • +4
13 Comments
 
LVL 11

Expert Comment

by:kyodai
ID: 24037369
No, your variables need to be unique if you want to use them globally. If you put the stack name in the variable name like "intStack1A" you can also use "intStack2A" without any problems.
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 200 total points
ID: 24037371
Of course. Although, I don't really see what the use of this is ... Could you give a bit more information/context about what you're trying to do ?
0
 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 24037788
int a,b; // Stack A
main() {
  int a,b,c; // Stack B

  {
 
      int a,b,c,d; // Stack C
 
  }

}
0
 
LVL 17

Expert Comment

by:CSecurity
ID: 24037857
sure! you have 3 stacks:
A: 1 2 3
B: 1 2 3 4
C: 1 2 3 4 5

this doesn't cause a problem. you have 3 stacks.
regards
0
 
LVL 10

Expert Comment

by:Korbus
ID: 24046287
If the items you are putting on the stacks are much larger than integers, you might want to put POINTERS to your variables on the various stacks, rather than the vaules themselves. (eliminates duplication of data in memory)

The other advantage to using pointers is: if you change a value for one variable,  that variable's value would change in all the other stacks too.
0
 

Author Comment

by:zizi21
ID: 24055518
sorry for the late reply...

i was thinking of such thing as reusing stack codes again and again instead of creating different stacks..i think,,,there is no such thing..
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 84

Expert Comment

by:ozo
ID: 24055615
what is the code that you are thinking of reusing, and what were you thinking of reusing it to do?
0
 

Author Comment

by:zizi21
ID: 24055809
i was just being lazy to have few stacks with the only difference of have additional items...i thought, of declaring a stack code once and then, reuse it ..looks a bit professional..i am wrong i guess...

lets say i have stack A it has item a and b.

now, i need to declare another stack called it stack B it has item a, b, c.

i thought, it was tiresome to write different push operations for various stacks...why not try to see if cud reuse....
0
 
LVL 84

Expert Comment

by:ozo
ID: 24055826
how is stack declared?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24057606
>> looks a bit professional..i am wrong i guess...

Why do you say you're wrong ?

What makes you think that you can't do this ?


Also, refer to my earlier post : http:#24037371
0
 

Author Comment

by:zizi21
ID: 24065065
i am trying to do it and i cant seem to get it right..i have removed a lot variables...

typedef struct box
{
int height;
int width;
}BOX;
typedef struct holder
{
BOX * boxes;
int top;
}HOLD;

Now, i am trying to add to more variables to the BOX struct...how do i do that...just some guidance or link to tutorial would be appreciated.
0
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
ID: 24065493
typedef struct
{
int height;
int width;
}BOXA;

typedef struct
{
BOXA box
int top;
}BOXB;
0
 

Author Closing Comment

by:zizi21
ID: 31565235
Thanks a lot.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Certified Pentester Exam - need assistance on compiling an exploit 6 375
An API detour question 7 79
smtp c source code 7 47
IIS Log files on Exchange 2013 server 6 85
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now