Junior — Middle
Can you name the main data structures used in programming?
sobes.tech AI
Answer from AI
The main data structures in programming include:
- Arrays — ordered collections of elements of fixed size.
- Lists — dynamic collections, for example, List<T> in C#.
- Stack — a structure with access based on LIFO (last-in, first-out).
- Queue — a structure with access based on FIFO (first-in, first-out).
- Hash tables (Dictionary, Hashtable) — for quick access by key.
- Trees (e.g., binary search trees) — hierarchical structures for sorted data.
- Graphs — for representing network connections.
Example of using a stack in C#:
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);
int top = stack.Pop(); // top == 2