-
STL code
I'm trying to find code that is used in the STL.
I have an assignment where we are to use stacks / queues, but he wants us to build the stack using a class and write our own functions for push/pop. I've got my program working using STL stuff, but now need to modify it and write my own class/functions. I'm not really sure what I need to do, and honestly don't understand why he likes to make us do things like this ( I get once or twice at the beginning, to get us to appreciate other people's work and how they've made things easier for us...but we're beyond the first or second program at this point and get that it's nice that someone wrote these libraries for us to use ...)
Can you point me in a direction to how to read / find the code that is written for these things so I can make an attempt at writing my own?
-
The point is that you should understand how these things work and get familiar with writing algorithms. You should not look at some STL code. You should make your own code.
Start with lining out the requirements: what functions should be there and what should they do?
Then write a flowchart describing how these functions would go about the task they need to do.
Then translate to code.
Check back if you get stuck with any of these steps.
-
The whole point of your current exercise is to reason out how to implement such things on your own. It is not to take the good work someone else has done (the authors of the STL) and repackage it. The point of the exercise is that you describe what a stack or a queue is, work out how what data structures are needed to represent it, and then reason out how you push or pop elements onto those data structures.
You will be wasting your time looking at STL source right now. Even using the basic techniques, let alone code, from the STL will ring alarm bells for whoever marks your exercise - not even prodigies at your stage of learning would use them, unless they have cheated.
-
Having used the STL for a long time I wouldn't even look at the source code for it. The source for the Microsoft version of the STL is atrocious. You would be better served analyzing the core data structure and then synthesizing your own code. I assure you that you will gain nothing but a headache by looking at the STL source.