C programming and data structure.?
hello friends! i am getting difficulty in understanding the concept of abstract data types in data structure.i searched a lot about it and what i concluded about adt is that "adt are such user defined data types on which we can't perform certain operations directly in order to perform any operation we need to make function with the help of which we can manipulate data" have i got the concept of adt correct? is this definition right? kindly help me and thanks in advance. Plz help me and tell me what I understood about ADT is correct or not?
- husoskiLv 71 month ago
Different writers have different definitions of what an abstract data type is, and those programming languages that have direct support for defining abstract types (C is not one of them) tend to do so differently. So, memorize what your textbook and instructor say for your exams. That will be a useful starting point and it's what you need to get your best grade in the course.
For your own future use, you might take a look at another book, at the Wikipedia article, or other source on the web. The Wikipedia article's "Introduction" section begins with "Abstract data types are purely theoretical entities..." and then lists a number of ways they are used.
The "abstract" part should be easy to understand. Some parts of the type are left undefined because they aren't important to the basic purposes of the type. If you have a List as an abstract type, the data type of the list entry is usually irrelevant. What's important is the set of operations you can perform on a List. The same operations apply equally well to a list of ints as to a list of doubles, arrays, or some user-defined struct type.
The bit about "can't perform certain operations directly" is more a matter of good software design rather than being an ADT "rule". You'll learn more about this in object-oriented programming, where "encapsulation" is one of the key design principles.
- Jogger2425Lv 61 month ago
IMO, that's a reasonable description of an ADT.
My knowledge of C is 22 years out of date. But, from what I remember, a C data structure falls short of enforcing that definition. A C programmer can glue different data fields together into a single entity using the "struct" keyword. But, C lacks provision for specifying visibility as "private", "protected", or "public". Everything in a "struct" is visible whenever the entity is visible. So, someone writing code to use a "struct" isn't forced to access the data via methods. Direct access is allowed. Also, I don't recall that C allows methods to be defined in a "struct".
If you use C++, on the other hand, you can specify visibility. This allows a programmer who creates a class to force programmers who create code that uses that class to use methods specified by the programmer who created the class. And C++ allows for member functions in a "class" or a "struct".
Factoid: In C++, a "struct" and a "class" are nearly the same. The difference is, default visibility for members of a "struct" is public, but private for a "class".
By the way, integers and floats are abstractions. For example, Consider an integer in the real world, vs. an int / integer data type in a program. There is no limit to the maximum or minimum values of a real world integer, but those limits exist in a computer.