Implementing Stack Data Structures in Java
A stack is a linear data structure that restricts insertion and deletion operations to one end—commonly referred to as the top. This constraint enforces a Last-In-First-Out (LIFO) behavior: the most recently added element is the first to be removed.
Core Terminology
Top: The active end where all push and pop operations occur.
Bottom: The fixed ...
Posted on Fri, 24 Jul 2026 16:29:29 +0000 by elhelaly1999
Linked List Operations and Array-Based Implementations
Header File Inclusion
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
Data Type Defniition
Using a type alias improves maintainability and simplifies type changes across the codebase:
typedef int ElementDataType;
Node Structure Definition
typedef struct ListNode {
ElementDataType value;
stru ...
Posted on Tue, 21 Jul 2026 16:18:22 +0000 by iskawt
Detecting Cycles and Removing k-th From End Using Two-Pointer Techniques
Given a singly linked list, determine weather it contains a cycle. Return true if a cycle exists; otherwise, return false. The solution must use O(1) auxiliary space.
This problem is classically solved using Floyd’s Cycle Detection Algorrithm — also known as the "tortoise and hare" approach. Two pointers traverse the list at different ...
Posted on Mon, 20 Jul 2026 16:57:01 +0000 by christian_phpbeginner
C Programming: Pointers, Linked Lists, and Delegates
1. C Language Examples of Array Pointers, Pointer Arrays, Function Pointers, and Pointer Functions
Pointer Array
An array where each element is a pointer is called a pointer array.
int *ptr_arr[10];
#include <stdio.h>
int main() {
int arr1[] = {1, 2, 3, 4, 5};
int arr2[] = {6, 7, 8, 9, 0};
int arr3[] = {1, 2, 3, 4, 5};
i ...
Posted on Wed, 08 Jul 2026 16:10:20 +0000 by seanstuart
LeetCode Problem 160: Intersection of Linked Lists
Intersection of Linked Lists
Problem Link
LeetCode 160
Problem Statement
Given the heads of two singly linked lists, headA and headB, return the node at which the two lists intesrect. If there is no intersection, return nullptr.
The linked lists must retain their original structure after the function returns. You are not allowed to modify th ...
Posted on Sun, 05 Jul 2026 16:14:54 +0000 by bobthebullet990
Implementing Deep Copy for Linked Lists with Random Pointers
The algorithm works in three phases:
Duplicate each node and insert it immediately after its original
Copy the random pointers from original nodes to their duplicates
Separate the interleaved lists into original and copy
C++ Implementation
class LinkedListCloner {
public:
Node* cloneList(Node* head) {
if (!head) return nullptr;
...
Posted on Mon, 29 Jun 2026 17:41:23 +0000 by bmdsherman
Reversing Linked Lists and Rotating Arrays: Efficient Algorithm Solutions
Reversing a Linnked List
Problem: Given the head of a singly linked list, reverse the list and return the new head.
Approach: Iterative Node Reversal
To reverse a linked list iteratively, we can utilize three pointers: current, previous, and temporary. The current pointer traverses the list, while the previous pointer keeps track of the reverse ...
Posted on Sat, 27 Jun 2026 17:54:19 +0000 by El Ornitorrico
Implementation of a Doubly Circular Linked List with Head Node
Funtcion Interface Definition
typedef int ElementType;
typedef struct _dnode {
ElementType value;
struct _dnode *previous;
struct _dnode *next;
} DNode;
typedef DNode* DList;
DList initializeList();
void appendNode(DList list, ElementType value);
bool isEmpty(DList list);
void forwardTraverse(DList list);
void backwardTraverse(DL ...
Posted on Sat, 27 Jun 2026 17:00:30 +0000 by m00ch0
Linked List Operations: Swapping Nodes, Removing Nth Node, Finding Intersections, and Detecting Cycles
Pairwise Node Swapping
To swap adjacent nodes in pairs, we utilize a dummy node to simplify edge cases. The core idea involves manipulating pointers to reverse each pair while maintaining proper linkage with the rest of the list. A cursor pointer tracks the predecessor of each pair being processed.
The termination condition varies based on whet ...
Posted on Sat, 20 Jun 2026 16:35:52 +0000 by matt6805
Merge Sort Implementation for Singly Linked Lists
Algorithm Overview
Split: Use slow-fast pointer technique to locate the midpoint and partition the list into two halves.
Recurse: Apply the same sorting procedure recursively on both halves.
Merge: Combine the two sorted sublists into a single sorted list using a linear-time merge step.
Implementation
class ListNode {
int value;
ListN ...
Posted on Fri, 19 Jun 2026 17:24:15 +0000 by brainstem