Fading Coder

One Final Commit for the Last Sprint

Introduction to C++ Templates

Generic Programming Consider an example: How to implement a generic swap function? In C++, function overloading allows us to use the same function name for different types. For example: void Exchange(int& a, int& b) { int temp = a; a = b; b = temp; } void Exchange(double& a, double&...

C++ Fundamentals: Variable Swapping and Syntax Comments

Exchanging Variable Values Directly assigning one variible to another overwrites the original data, preventing recovery of the initial value. To successfully interchange contents between two storage locations, a temporary buffer is necessary. Consider this implementation using standard integer types...

Understanding C++ Special Member Functions and Operator Overloading

In C++, a class definition automatically receives several special member functions when they are not explicitly declared by the programmer. These compiler-generated routines handle object lifecycle management and initialization. The primary functions include the default constructor, destructor, copy...

Implementing C++ Classes with Constructors, Friends, and Static Members

Class T: Demonstrating Constructors and Static Members Header File: T.h #pragma once #include <string> class T { public: T(int val1 = 0, int val2 = 0); T(const T &source); T(T &&source); ~T(); void scale(int factor); void show() const; static int current_count(); static const std::...

Dynamic Memory Allocation and Generic Programming in C++

Heap Allocation with new and delete C++ replaces traditional C allocation routines with operators that seamlessly integrate object lifecycles. Primitive Data Allocation Fundamental types use straightforward syntax. Single items require new/delete, while contiguous blocks require new[]/delete[]. Mism...

Implementing a Dynamic Array Container in Modern C++

A custom vector implementation relies on managing three pointers that track the boundaries of allocated storage and initialized elements. This implementasion explores memory management strategies, proper deep-copy semantics, and iterator stability during reallocation. Core Architecture template <...

Building a TCP Chat Server with Winsock and Modern C++

Developing a concurrent chat server involves managing multiple simultaneous TCP connections while ensuring thread-safe message distribution. This implementation leverages the Winsock2 API alongside C++11 concurrency primitives to build a multi-user messaging platform supporting both direct messaging...

Advanced Competitive Programming Patterns in Interval Dynamic Programming

Merging Strings for Maximum Palindromes Given two strings $S1$ and $S2$, we aim to merge them into a single string $S3$ while maintaining the relative order of characters from the original strings. The goal is to find the maximum possible length of a palindromic substring within any such $S3$. A fou...

Implementing Queues with Stacks and Stacks with Queues in C++

Understanding Stack and Queue Implementations In C++, both stacks and queues are container adapters, typically built upon underlying containers like vector or deque. Their core concepts are Last-In-First-Out (LIFO) and First-In-First-Out (FIFO), respectively. 232. Implement Queue using Stacks Design...

Operator Overloading and Inheritance in C++

1. Increment Operator Overloading Pre-increment returns a reference, while post-increment returns a value. // Custom integer class class CustomInt { friend std::ostream& operator<<(std::ostream& output, CustomInt value); public: CustomInt() : data(0) {} // Pre-increment operator overlo...