hey friends i am working with a program of "stack of stack".....and i thought to work it out using inheritance....but i m stuck in it...
i thought to inherit both the stack - the parent stack and a stack element....from a single base class..
i mean i am in dilemma of how to use inheritance...the basic functions of a stack wud be...push, pop, view, isempty...etc.
for push d functions wud differ as push(stack) in parent stack and push(int) in mini stack....
same for oders...
so any suggestions...?? or shud i drop dis idea??? :|

or push d functions wud differ as push(stack) in parent stack and push(int) in mini stack....

Yeah....whatever.
Please read the rules (part: keep it clean)

How about you use a vector for your 'mini-stack' and then make a map of vectors for your big (stack-)stack

Since if written this samplecode already for someone else:

std::map <std::string, std::vector<int> > array;
  array["v1"].push_back(1);
  array["v1"].push_back(13);
  array["v1"].push_back(344);
  array["v2"].push_back(344);

  cout << "The map 'array' has " << array.size() << " vector(s)\n";
  cout << "The vector v1 in map 'array' has " << array["v1"].size() << " numbers\n";

Yeah....whatever.
Please read the rules (part: keep it clean)

How about you use a vector for your 'mini-stack' and then make a map of vectors for your big (stack-)stack

Since if written this samplecode already for someone else:

std::map <std::string, std::vector<int> > array;
  array["v1"].push_back(1);
  array["v1"].push_back(13);
  array["v1"].push_back(344);
  array["v2"].push_back(344);

  cout << "The map 'array' has " << array.size() << " vector(s)\n";
  cout << "The vector v1 in map 'array' has " << array["v1"].size() << " numbers\n";

ok...yaaa...got it...sorry...wont repeat that mistake... :) ....net chat... :)
and umm...i didn't get much of your code...if you can simplify it... :|

I can't, but I can explain. A vector is a sort of an array which can grow and shrink on the fly. In this example I use std::vector<int> to indicate I'm going to store ints in it.

Now for the somewhat harder part.
The map contains a string and a vector of ints. The string is sort of it's ID. The vector the contents:

Attachments naamloos.JPG 11.79 KB

I can't, but I can explain. A vector is a sort of an array which can grow and shrink on the fly. In this example I use std::vector<int> to indicate I'm going to store ints in it.

Now for the somewhat harder part.
The map contains a string and a vector of ints. The string is sort of it's ID. The vector the contents:

ohkk...got it now...actually i knew the vector...but not the map...but its clear now... :)
thanks for help... :)

This article has been dead for over six months. Start a new discussion instead.