区分数据类型和数据结构 [英] Distinguishing Data Types and Data structures

查看:151
本文介绍了区分数据类型和数据结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗯,不管怎么说,即使阅读了很多教科书(真的很多)和互联网上很长一段时间,我仍然不能完全理解两个提到的东西之间的区别。



为简化问题,根据我们说维基百科的数据类型是:


各种类型的数据,如实数,整数或布尔值,可确定该类型的可能值;可以对该类型的值执行的操作;数据的意义;并且可以存储该类型的路径值。


它主要是实现一些抽象数据类型像实数或整数。



所有好的,然后是数据结构:


是一种在计算机中组织数据的一种特殊方式,可以高效地使用。[1] [2]数据结构可以实现一个或多个特定的抽象数据类型,它们是指定操作合同及其复杂性的手段。相比之下,数据结构是由ADT 提供的合同的具体实现。


所以数据结构是一个ADT的实现,就像一个堆栈或队列一样。



但是不会使它成为数据类型吗?



我可以真正看到的是,数据类型可以从真正简单的事情,没有任何结构组织到复杂的数据结构,真正重要的是,它们是ADT的实现,镜像重要它们可以被设想为单个实体(列表或树),但是数据结构必须至少包含某种逻辑或数学组织来分类为数据结构,但可悲的是,这种差异会使许多实体数据结构和数据类型同时存在。



那么简单的简单(数据类型)和(数据结构)之间的固体差异是甚么?

我很乐意接受一个答案,指出一个关于这个话题的具体书籍,这足够深入解释所有这些问题,如果有人可以向我推荐一些有关C中数据结构的好书。

解决方案

在C中,数据类型是一种语言级的构造。有限数量的预定义类型( int char double 等)和几乎无限数量的派生类型(数组类型,结构类型,联合类型,函数类型,指针类型,原子类型(后者在C11中是新的))



任何类型可以通过 typedef 声明给出一个简单的名称。对于除功能类型或不完整类型以外的任何类型,您可以拥有该类型的对象每个对象占用一个连续的内存区域。



C中可以存在的类型在C标准的6.2.5节中完全描述;请参阅 N1570草案。另一方面,



数据结构是由您自己的代码定义的结构。该语言没有定义链表,或二进制树或哈希表的概念,但可以实现这样的数据结构,通常通过在派生数据类型之上构建它。通常,没有这样的东西作为一个链接的对象。链接列表数据结构的一个实例由相关对象的集合组成,只有您的代码的逻辑将该集合转换为一个连贯的实体。但是,您通常会有一些数据类型的对象,您的程序用于将引用链接到链表数据结构,也可能是结构或指向结构的指针。



您通常会有一组操作数据结构实例的函数。这些功能是否是数据结构的一部分是一个困难的问题,我不会在这里尝试回答。



例如,一个数组可以被认为是一个数据类型和数据结构;更准确地说,您可以将其视为使用现有阵列类型实现的数据结构。


Well, somehow even after reading in a lot of textbooks (really a lot) and on the Internet for a long while I still can’t completely comprehend what the difference between the two mentioned things is.

To simplify the question, according to let’s say Wikipedia a data type is:

a classification identifying one of various types of data, such as real, integer or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of that type can be stored.

with it being mostly the implementation of some Abstract data type like the real numbers or the whole numbers.

All good, then comes the data structure:

is a particular way of organizing data in a computer so that it can be used efficiently.[1][2] Data structures can implement one or more particular abstract data types., which are the means of specifying the contract of operations and their complexity. In comparison, a data structure is a concrete implementation of the contract provided by an ADT.

So a data structure is an implementation of an ADT like say a stack or queue.

But wouldn’t that make it a data type as well??

All that I can truly see is that a data type could range from really simple things without any structural organization to sophisticated structures of data what really counts is that they are an implementation of an ADT mirroring the important aspects of it and that they could be envisioned as a single entity like ( a list or tree), but data structures must contain at least some sort of logical or mathematical organization to classify as a data structure, but sadly this difference would make many entities both a data structure and a data type simultaneously.

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

I would gladly accept an answer with specifying a specific book about this topic which goes deep enough to explain all this matters, also if someone can recommend me some good books about data structures in C.

解决方案

In C, a data type is a language-level construct. There are a limited number of predefined types (int, char, double, etc.), and a practically unlimited number of derived types (array types, structure types, union types, function types, pointer types, atomic types (the latter are new in C11)).

Any type may be given a simple name via a typedef declaration. For any type other than a function type or an incomplete type, you can have objects of that type; each object occupies a contiguous region of memory.

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

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, or a binary tree, or a hash table, but you can implement such a data structure, usually by building it on top of derived data types. Typically there is no such thing as an object that's a linked list. An instance of a linked list data structure consists of a collection of related objects, and only the logic of your code turns that collection into a coherent entity. But you'll typically have an object of some data type that your program uses to refer to the linked list data structure, perhaps a structure or a pointer to a structure.

You'll typically have a set of functions that operate on instances of a data structure. Whether those functions are part of the data structure is a difficult question that I won't try to answer here.

An array, for example, can be considered both a data type and a data structure; more precisely, you can think of it as a data structure implemented using the existing array type.

这篇关于区分数据类型和数据结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆