0

I'm a little bit confused. Wikipedia says that Array is a data structure:

In computer science, an array data structure, or simply an array, is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key.

Stack and queue are also data structures. Learn.js says that array can work with data structures such as stack and queue.

So, my question is... it turns out that data structure can also be structured with another data structure? Or, as far as I understand, array is a slightly different data structure, unlike stack and queue. The array structures its data by index, while stack and queue structure data by order of entry (FIFO / LIFO). And it turns out that different data structures by "type" can be structured by other data structures of a different "type"? ... Or I misunderstood something ...

0

2 Answers 2

2

"Data structure" is a very general idea, and data structures exist at different levels of abstraction.

So "array" and "object" are very basic data structures -- an array is just a linear collection of data indexed numerically, while an object is a collection with named elements.

"Stack" and "queue" are higher level abstractions. They're typically implemented using objects and arrays to hold the raw data, and they provide additional operations that reflect the way these abstractions are used.

Sign up to request clarification or add additional context in comments.

4 Comments

Got it. Also as far as I know, there's call stack. It turns out that stack can also structures calls of function, not only arrays or objects. So, technically stack or queue can be used for structuring any type of data, right?
"stack" is another general concept. The "call stack" is not a data structure that the application deals with, I was talking about stacks used in the application code itself.
Seems like u got me wrong. I think (maybe I'm not right) that "stack" is a data structure. And "stack" structures calls of function like it structures arrays or objects
A stack is basically any data structure that implemetns LIFO operations.
1

In most languages an array is a fundamental data structure and stack and queue are separate data structures. (They might be built using an array, but that is another story.)

In JavaScript, an Array has a few convenience functions that allow it to serve as either a stack or queue. If you need a stack in JavaScript, you can create an array object and only use the push/pop methods instead of accessing elements by their index.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.