// Create a min-heapPriorityQueue<Integer> minHeap = new PriorityQueue<>();// Add a new element to the heapminHeap.add(5);// Remove and return the smallest element from the heapminHeap.poll();
Python
# # Create a list to serve as a container for the min-heapminHeap = []# Convert the list with elements into a min-heapheapq.heapify(minHeap)# Add a new element to the heapheapq.heappush(minHeap, 5)# Remove and return the smallest element from the heapheapq.heappop(minHeap)
C++
// Create a min-heappriority_queue<int> minHeap;// Add Add a new element to the heapminHeap.push(5);// Remove the smallest element from the heapminHeap.pop();// Return the smallest element from the heapminHeap.top().val;
Stack Manipulation
Java
// Create a stackStack<Integer> stack = new Stack<>();// Add a new element to the stackstack.push(10);// Remove and return the top element from the stackint topElement = stack.pop();// Return the top element from the stackint topElement = stack.peek();