Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
3 votes
2 answers
105 views

Huffman Coding implementation in C++

Here is an implementation of compression with Huffman coding. It works well by my testing. It compresses a 1 GB string in about 30 seconds, and decompresses in about 15 seconds with VisualStudio 2022 &...
3 votes
1 answer
75 views

Queue using circular linked list

I'm reading through Algorithms Fourth Edition by Sedgewick and doing some of the practice exercises in C++11 instead of Java. Exercise 1.3.29 is to write a Queue that uses a circular linked list, ...
1 vote
1 answer
39 views

Implementation of a multi-dimensional array as a single memory buffer [Part 2]

A couple days ago I posted my first implementation of my data structure here, which implements a cache-optimized tensor representation. I have worked the ideas from the responses into my ...
3 votes
2 answers
87 views

Bookshop Management System

I am doing a beginner c++ project, where you can add books, display books. I'm planning on adding other functionalities like searching the database and checking if a book is available for purchase. I ...
8 votes
3 answers
675 views

A generic binary search function in C++

I have written the following generic function template: ...
0 votes
2 answers
574 views

Next level Improved Sieve of Eratosthenes

This is the next development for the Sieve of Eratosthenes algorithm, where all the multiples of 2,3 and 5 are eliminated, which will not take any memory or time. As my last question Improved Sieve of ...
2 votes
1 answer
83 views

Finding anagram groups using hashing and mapping the alphabet to random numbers

I was solving Group Anagram problem in leetcode. Link for the problem https://leetcode.com/problems/group-anagrams/ Below is the code which I wrote ...
  • 187
3 votes
3 answers
85 views

Implementation of a multi-dimensional array as a single memory buffer

There is an updated version of this code with some of the recommended changes made here. I have created an implementation of a multi-dimensional array which utilizes a single continuous memory buffer ...
8 votes
7 answers
4k views

Improved Sieve of Eratosthenes

How can I get to a perfect coding for this algorithm? I made the mathematical theorem, which is a development of the Sieve of Eratosthenes algorithm. I might use some help in coding. You can find the ...
6 votes
2 answers
71 views

LeetCode 126: Word Ladder II -- Memory limit exceeded

I am trying to solve LC126, and got a memory limit exceeded for the following solution. I've seen the answer here -- so I'll try to use Dijkstra as well, but I would like to understand why I get the ...
  • 266
2 votes
3 answers
102 views

Find long palindrome multiplications in modern C++

I'm a former C# programmer, updating my rusty C++98 (perhaps I should try Rust instead) to modern C++20. My main goal is to get used to C++ standard library types and algorithms. I chose to solve a ...
2 votes
1 answer
82 views

Reimplementation of Diep.io in C++ with SFML and Box2D

Here's my attempt at reimplementing part of https://diep.io/, a 2D game where tanks battle with each other. The tanks are circular and they have cannons which fire bullets. The bullets can hit other ...
  • 123
1 vote
2 answers
63 views

A card game deck/hand manager

I started writing a card game in C++ yesterday, just as something to do to familiarize myself with the language. When I showed it to a friend of mine in the compsci field he said I should share it ...
  • 11
5 votes
5 answers
869 views

Palindrome Permutation string

I’m starting to learn C++ by doing a lot of exercises, and I need your help so I can improve, Here is how it goes, I will try to solve an exercise and post both the ...
6 votes
3 answers
825 views

Space encoder for URL

I’m starting to learn C++ by doing a lot of exercises. I want you to point me to where/what improvements I can do to make my code better. The exercise: write a URLencode function that takes a string ...
3 votes
2 answers
150 views

Data format conversion program code

This program converts a proprietary text data format to the conf or ini file format. I have some questions on the code: Is the high level code design coherent and easy to read? Does the code use '...
  • 2,289
2 votes
1 answer
62 views

Absolute value meta programming

I am implementing a generic absolute value function that handles signed and unsigned integer values correctly over the input type's domain. The std::abs(...) ...
  • 21
3 votes
2 answers
559 views

Printing a C++ struct

Critique? ...
  • 1,404
0 votes
0 answers
76 views

C++ PEXT/PDEP implementations

The common implementations usually reference: https://github.com/fmatthew5876/stdcxx-bitops/blob/master/include/bitops.hh I styled my version to match (except for the ...
4 votes
1 answer
90 views

Bin-packing C++ solution using multi-map

The need (context). Several times a day, we need to migrate a set of digital assets from one system to another. The process uses memory (the assets are held in memory for a short time) and we need to ...
  • 197
6 votes
2 answers
281 views

Codeforces #806 Problem D: Double Strings

I tried solving the following problem by following the suggested approach to solving the problem in the problem tutorial. However, the online judge still says my solution exceeds the time limit. Is ...
  • 61
2 votes
1 answer
94 views

Advice for optimization of a custom doubly Linked List class

This is my custom implementation of a double Linked list. Code is apparently working fine. Need advices on improvement and/or optimization. This is a tiny academic side-project. I am still pretty ...
  • 53
13 votes
3 answers
2k views

Sum of FizzBuzz numbers with modern C++

I am learning to write more modern C++, since my C++ is from the 1990s (I'm a C# programmer). I need to get used to the STL algorithms and such. So I tried some kata, summing up numbers in a given ...
2 votes
3 answers
83 views

A constexpr, const correct matrix class with compile-time checks

I've expanded, and enhanced my matrix class which uses, aside from dynamic memory for the elements, only 3, const literals. These are rows, cols, and a ptr. The methods are all constexpr and the ...
  • 173
5 votes
2 answers
133 views

C++ wrapper to call Python code

I'm wondering if the following Python wrapper for C++ I'm developing is worth expanding upon and including in my portfolio. If so, I plan to add more parameter options and return types. The problem is,...
2 votes
1 answer
73 views

A parse function for text line with fields separated by a comma with the known number and their type

I am trying to parse a line with a fixed amount of fields and known types. ...
  • 23
3 votes
2 answers
119 views

Leetcode 14. Longest Common Prefix beats only ~50% of C++ solutions

The task is to find the longest common prefix. While I had no trouble to find the solution, I'm interested in the statistics of my code: Runtime: 7 ms, faster than 56.36% of C++ online submissions ...
9 votes
1 answer
755 views

Porting C-style socket to CPP class

I am porting the C-style socket to design a simple wrapper around the telnet client in CPP. The telnet protocol is accomplished by using libtelnet in C. The C-style code for this wrapper is reviewed ...
  • 429
3 votes
1 answer
72 views

A periodic implementation for C++ using Grand Central Dispatch

I have a C++ project which needs a few periodic timers. I have created a timer class for this project using Grand Central Dispatch. I tried using boost::asio, but ...
3 votes
3 answers
95 views

Input validation of a signed double (in C++)

I am a beginner, who is just learning the language (C++) from C++ Primer. I have been trying to build a side pico-project by writing functions for validation of user input for an signed double. The ...
  • 53
4 votes
1 answer
141 views

A toy application of pub/sub using C++ for self-learning

Firstly, I apologize for the lengthy post. I was not sure which code I should include. In practice of c++, I am writing a toy application for pub/sub using c++17. ...
4 votes
1 answer
72 views

Timer thread implementation

I've implemented a timer thread whose job is to call functions at a certain interval. The functions may be called multiple times if their interval > 0 millisec otherwise only one time. Even if the ...
3 votes
1 answer
73 views

Hardware abstraction in C++ on STM32F4

I've recently watched a few talks on implementing easy-to-use hardware abstraction layers in C++ for use on embedded devices such as ARM Cortex-based microcontrollers such as the STM32F4 that I am ...
6 votes
2 answers
1k views

Linked List implementation in c++ with all functions

I wrote my implementation to Linked List. And I tried to implement all the functions in the standard library list in CPP! I need a review for it to improve it and improve my coding skill. I also will ...
2 votes
1 answer
56 views

C++ Refactored graph again, separated property maps from Graph type

This is yet another improvement from my graph class - Link Now property maps are no longer parts of Graph type, they are just stored in a member variable. This ...
  • 1,643
5 votes
1 answer
60 views

Composite expected in C++

I'm interested in creating a successor to the expected monad in C++. Specifically I want it to be capable of storing error which may has one of many types, and a ...
  • 53
2 votes
1 answer
58 views

Queue Linked List based implementation in C++

I wrote my implementation to Queue Linked List based. And I need a review for it to improve it and improve my coding skill. I also will put this implementation on my GitHub account. ...
3 votes
3 answers
175 views

Discussing approaches for converting Enum to String

I need to convert the ENUM to a respective string value for which I came up with two approaches and I'm trying to see why would a second approach be better than the first one if even in terms of ...
  • 362
2 votes
2 answers
95 views

Queue array based implementation in C++

I wrote my implementation to Queue array based. And I need a review for it to improve it and improve my coding skill. I also will put this implementation on my GitHub account. Thanks in advance. ...
2 votes
1 answer
68 views

C++ Graph class with multiple property maps (edit)

I wrote an improvement from my previous graph class: Link ...
  • 1,643
3 votes
1 answer
234 views

Maximum number of words found in sentences

You are given an array of strings sentences, where each sentences[i] represents a single sentence. Return the maximum number of words that appear in a single sentence. Example Input: sentences = [&...
user avatar
1 vote
1 answer
68 views

Polish Notation in C++

This is my homemade Polish Notation implementation in C++. I need a review for it to improve it and improve my coding skill. I also will put this implementation on my GitHub account ...
4 votes
1 answer
95 views

C++ Binary search using SIMD

Recently I found that the binary search (std::ranges::lower_bound and std::ranges::upper_bound) is the main bottleneck in my ...
  • 1,643
4 votes
1 answer
70 views

Yet another mathematical vector class

This is an implementation of a mathematical vector. I am currently working on a linear algebra project and before proceeding further with other classes (matrix, polar_vector etc.) I would like to have ...
2 votes
2 answers
79 views

Stack Linked list based implementaion in C++

This is my second implementation of the Stack in c++. I already implemented it as an array-based here I need a review for it to improve it and improve my coding skill. I also will but this ...
2 votes
2 answers
111 views

Stack array based implementation in C++

I wrote my implementation to Stack array based. And I need a review for it to improve it and improve my coding skill. I also will but this implementation on my GitHub account. One more thing: I am not ...
0 votes
0 answers
26 views

Does this HTTP library API make sense for handling small in-memory message bodies as well as large stream-based messages?

I'm writing a HTTP server and client in C++20. It started with a simple API, string call(string url) which worked great for another project. The API uses implicit ...
  • 1
4 votes
3 answers
108 views

C++ B-Tree serialization/deserialization

Yesterday I wrote a serialization/deserialization for my B-Tree library. Since the code for whole tree is too large to upload here, I'll upload only serialization/deserialization and node class ...
  • 1,643
2 votes
2 answers
61 views

C++ distributed enumeration alternative

Application: replacing enum type / description tags in modular software, allowing adding new enum values without updating one definition. Say we have a video processing pipeline not unlike gstreamer. ...
  • 813
1 vote
0 answers
33 views

C++20 B-Tree v1.0 with disk file supports and perf test

I've improved my in-memory B-Tree (Link) to release a B-Tree with support for memory-mapped disk files and fixed-size allocators: Repository: https://github.com/frozenca/BTree Code: ...
  • 1,643