Hi!
Can anybody tell me about abstract data types in C++ with example and how they differ from
normal data types.
I will be very thankful...
Thanks in advance
Hi!
Can anybody tell me about abstract data types in C++ with example and how they differ from
normal data types.
I will be very thankful...
Thanks in advance
I am not sure of my definition of abstract data types, but here's something on it:
http://g.oswego.edu/dl/libg++paper/libg++/node2.html
Wikipedia also offers a nice definition: http://en.wikipedia.org/wiki/Abstract_data_types
Programming is a form of art.
Google/Wikipedia are your friends for questions like this.
Think of ADTs as a more object oriented / organized way of representing data throughout your program.
Think of a room. Your room might have a table, a bookshelf, your computer, walls, lighting, etc , but the actual "room" isnt a single physical object, its an abstract idea. Another common example of this is if you have a shape. You might draw a triangle, circle, quadrilateral etc, but you cant simply draw just a shape because we have categorized them. So, while we have an abstract idea of shapes, there is no concrete, simple shape. Basically, its a way of organizing/storing/moving a general category of data rather than the specific data itself.
Last edited by goldz; 01-03-2007 at 03:53 AM.
To my mind, an "abstract" data type is labelled as such because of the behaviour it models rather than the actual data which it holds.
For example, in C++, we have containers such as queues, stacks and vectors. There's a good chance that in all 3 cases, the actual data is stored in exactly the same way! (no guarantees though). However, what should be striking when you read any reference or tutorial about these abstract types is that the behaviour associated with them are all fundamentally different.
- a queue, is a first-in, first-out structure - so you would usually insert an object, or a data item at the back, and retrieve one from the front
- a stack is a first-in, last-out structure - so you would insert objects to the 'top' and retrieve them from the 'top'
- a vector works more like a more versatile array, with random access.
Compare this with built in types - for built-in types, the focus is on the sort of data they hold. Their behaviour is more of a set of simple constraints, such as being unable to store a float or double inside an int, and the way the data is represented when you print it on to the console screen. eg.
- an 'int' is called as such because it holds a whole 'integer' number
- a 'float' is called as such, because it holds a "floating point" (real) number
- a 'bool' is called as such, because it holds a boolean 'true/false' value.
Unlike Abstract Data Types (ADTs) None of these constraints for built-in types really specify ways in which the data may be used - The amount of abstraction associated with these types is minimal.
Last edited by Bench82; 01-04-2007 at 10:48 AM.