programming_languages:basic_data_structures

This is an old revision of the document!


Basic data structures in different languages

Having dealt with multiple different programming languages creates some confusion how and in which place the data structures are implemented in each of the languages. This page tries to provide some overview of basic ds.

LIFO

Stack<E>

or

Deque<Integer> stack = new ArrayDeque<Integer>();

Operations:

empty, pop, peek, push, search
// simple lists
letters = []
last_item = letters.pop()

Operations:

append, pop

FIFO

Collection interface Queue

  1. Thread-safe: PriorityBlockingQueue
  2. Not Thread-safe: PriorityQueue, LinkedList

Operations

add()
peek()
element() throws NoSuchElementException when queue is empty
remove() removes and returns the head of the queue
poll()
size()
from collections import deque
first_item = numbers.popleft()

Operations:

append, pop, popleft
Math.min, Math.max
(int) Math.pow(2, 3)
str.indexOf // (first occurence of Character/String;  + index to start; Returns -1 if not found, else idx
str.charAt // Character
str.substring(int beginIndex, int endIndex) // actual start (=0), but end is lenght)
  • programming_languages/basic_data_structures.1571529080.txt.gz
  • Last modified: 2019/10/20 01:51
  • by phreazer