Distinguishing Data Types and Data Structures

Well, somehow even after reading many tutorials (really a lot) and on the internet for a long time, I still can't fully understand what is the difference between the two things mentioned.

To simplify things, according to Wikipedia, the datatype is:

a classification that identifies one of the various data types, such as real, integer, or Boolean, which defines the possible values ​​for that type; operations that can be performed on values ​​of this type; meaning of data; and a way to store values ​​of this type.

as it is basically an implementation of some abstract data types like real numbers or integers.

All is well, then comes the data structure:

is a special way of organizing data on a computer so that it can be used effectively. [1] [2] Data structures can implement one or more concrete abstract data types, which are a means of defining the contract of operations and their complexity. By comparison, a data structure is a concrete implementation of the contract provided by ADT .

Thus, a data structure is an ADT implementation such as a stack or queue.

But wouldn't that make it a datatype as well?

All I really see is that the data type can range from really simple things without any kind of structural organization to complex data structures, what really matters is that they are an ADT implementation reflecting important aspects of this and that they can be represented as a single object such as (list or tree), but data structures must contain at least some logical or mathematical organization to be classified as data structures, but unfortunately this difference will lead to that many objects will represent both data structure and data type at the same time.

So what is the solid difference between simple simple (data type) and (data structure)?

I happily accept the answer by pointing out a specific book on the topic that is deep enough to explain the whole thing, also if someone can recommend me some good books on data structures in C.

+3


source to share


3 answers


In C, a data type is a language-level construct. There are a limited number of predefined kinds ( int

, char

, double

etc.), and a virtually unlimited number of derived types (array types, types of structures, Types association function types, types of pointers, atomic types (the latter in new C11)).

Any type can be given a simple name through a declaration typedef

. For any type other than a function type or incomplete type, you can have objects of that type; each object occupies a contiguous area of ​​memory.

The types that can exist in C are fully described in section 6.2.5 of the C standard; see, for example, project N1570 .



A data structure, on the other hand, is a construct defined by your own code. The language does not define the concept of a linked list, binary tree, or hash table, but you can implement such a data structure, typically by building it on top of derived data types. Typically, there is no such thing as a linked list object. An instance of a linked list structure consists of a set of related objects, and only your code's logic turns this collection into a coherent entity. But you will usually have an object with some data type that your program uses to refer to a linked list data structure, perhaps a structure or a pointer to a structure.

Typically you have a set of functions that operate on instances of a data structure. Whether these functions are part of a data structure is a tricky question that I won't try to answer here.

For example, an array can be thought of as both a data type and a data structure; more precisely, you can think of it as a data structure implemented using an existing array type.

+4


source


Referring> = C99:

There are two types of data types:

  • intrinsic: char

    , int

    , float

    , double

    , _Complex

    , _Bool

    , void

    (for some of them there is a variation on long

    and unsigned

    around)
  • : arrays, structures, unions, pointers, functions

The latter are built from the former and / or the latter.




So, to answer your question:

So what is the solid difference between simple simple (data type) and (data structure)?

The "data structure [type]" is derived from "simple simple data types" and / or other "data structure [type]" (s).

+2


source


The data type specifies the values ​​and operations allowed for a single expression or object; data structure is a storage area and algorithms that organize objects in that storage.

Example data types: int

; objects of this type can store integer values ​​of at least a range [-32767, 32767]

, ordinary arithmetic operations can be performed on these objects (although the result of integer division is also an integer that moves people around for the first time). You cannot use the index operator []

on int

, nor can you use the function operator ()

on an object int

.

For an example data structure, we can look at a simple stack. We will use an array as our storage region. We will define an additional integer element that will serve as the stack pointer - it will contain the index of the element that was recently added to the array. We define two algorithms - push

and pop

- that will add and remove items onto the stack in a specific order.

push: if sp is less than stack size then
        add 1 to sp
        write input to array[sp]
      else
        stack overflow
      end if

 pop: if sp is greater than 0 then
        get value from array[sp]
        subtract 1 from sp
        return value
      else
        stack underflow
      end if

      

Our stack data structure stores a number of objects of some data type, so that the last added item is always the first removed item, aka the queue with the last one in the first (LIFO). If we push the values ​​1, 2, and 3 onto the stack, they will slide out in the order of 3, 2, and 1.

Note that these are algorithms that distinguish data structures from each other, not the type of storage. If your algorithms add an element to one end of the array and pull it out from the other end, you have a first entry queue (FIFO). If your algorithms add elements to an array in such a way that for every element i

in the array a[i] >= a[2*i]

and a[i] >= a[2*i+1]

both values ​​are correct, you have a bunch.

+2


source







All Articles