describe the concept of arrays and stack,compare with code example
Answers
Explanation:
The main difference between array and stack is that an array stores elements of the same type while a stack stores elements of different types.
A data structure is a way of storing data elements in computer memory.
There are two types of data structures as linear and nonlinear data structures:
- Linear data structures store data in a sequential manner.
- Array and stack are two common linear data structures.
Explanation:
Stack:
A stack is a linear data structure in which elements can be inserted and deleted only from one side of the list, called the top. A stack follows the LIFO (Last In First Out) principle, i.e., the element inserted at the last is the first element to come out. The insertion of an element into stack is called push operation, and deletion of an element from the stack is called pop operation. In stack we always keep track of the last element present in the list with a pointer called top.
The diagrammatic representation of stack is given above first image:
Array:
An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. This makes it easier to calculate the position of each element by simply adding an offset to a base value, i.e., the memory location of the first element of the array (generally denoted by the name of the array).
Hope it helps!!!
If you want more information then ask me anytime :)
