Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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++...

0
votes
2answers
30 views

Stable-sorting all even numbers before odd numbers in a linked list

Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even ...
4
votes
0answers
23 views

Warped Audio Sample

I was asked this question and got no feedback, so I'd like to ask you for any feedback on my solution, Thanks! Think of an audio sample as a rubber-band that you want to pin to a musical time ruler. ...
-2
votes
0answers
39 views

Lock-Free Multiple-Producer & Multiple Consumer - Stack and Queue [on hold]

Update: The dequeue method was reading from Head multiple times. Update: Dequeue curr pointer can become null when looking for the last node. Update: I've switched to using C++ std 11 atomics and so ...
-4
votes
0answers
21 views

How do you properly organize data to compute multiple (independent) recursive filters at the same time taking advantage of SIMD instructions? [on hold]

I'm processing multiple (independent) Exponential Moving Average 1-Pole filters on different parameters I have within my Audio application, with the intent of smooth each param value at audio rate: <...
3
votes
1answer
61 views

Advent of Code 2018 Day 13 - Detect mine cart collisions

This is a solution to Advent of Code Day 13 (problem specification, test input), for which I was asked to read a layout of tracks and mine carts and detect 1) where the first crash would occur and 2) ...
2
votes
2answers
68 views

A recursive algorithm to find the number of distinct quantities of money from a pile of coins

Problem: find the number of distinct quantities of money that a pile of coins can make. The vector coins contains the values of the coins, and the corresponding ...
-1
votes
0answers
34 views

LeetCode 234. Palindrome Linked List, a TLE weird case [on hold]

Here is my AC submission. And I found a wierd circumstances when I remove this line dumyHead->next = NULL; my submission will yield a TLE. I know if I don't set ...
3
votes
1answer
92 views

Simple stringifying using << operator

Background I wrote my_length class and some code. my_length can be stringified using ...
-2
votes
0answers
14 views

Getting a Segmentation Fault after one iteration of the loop for text-based bluff(cheat) card game [on hold]

Please look into the following code for a text-based bluff(cheat)game. it should display the cards in hand for each user before their turn. ask for the cards they want to call, and then for the actual ...
3
votes
1answer
50 views

Game of Life implementation with no loops

I began implementing Game of Life for fun, then I challenged myself to implement the game with no loops. I only used STL Algorithms. I don't know how to make pretty GUI's yet but this will print the ...
3
votes
2answers
120 views

Stack implementation in C++ including min(), max() functions in O(1)

This implementation seems to work. I would love to get any suggestions / comments on how this code could be improved. Are there any potential memory management issues? Any additional methods that ...
3
votes
1answer
92 views

C++ Battleship player AI

Found this project online and looking for some guidance. I'm in the process of developing a Battleship AI that will play against different computer difficulties. The "barebones" part of the project ...
3
votes
5answers
669 views

Project Euler 92: count sum-squared-digits chains that reach 89

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1 85 → 89 →...
3
votes
3answers
93 views

A collection of vector functionals

I would like some feedback for a collection of what I call "vector functionals", by which I mean maps \$\ell\colon \mathbb{K}^{n} \to \mathbb{K}\$, where the field \$\mathbb{K} = \mathbb{R}\$ or \$\...
4
votes
1answer
60 views

Complex Newton's Method

I'm trying to build a complex Newton's method. I've submitted a PR here, where you can see the documentation and tests, as well as get a compiling example. I'd appreciate y'alls help reducing the ...
1
vote
1answer
42 views

Prepare a cross-platform QT C-wrapper class for unit testing and mocking

The situation I recently started a cross platform QT project (arm, linux-x86, windows) that aims to interact with CAN-Bus hardware. I want to learn and get used to unit testing from scratch as good ...
3
votes
1answer
94 views

value_ptr<T> - a C++11 header-only, deep-copying smart pointer that preserves value semantics for polymorphic and undefined types (updated)

My previous iteration was here. I've since finalized the concept as described in the title, and would appreciate any feedback GitHub Link Introduction: ...
7
votes
1answer
543 views

Sort int array by frequency then value

Problem Take an array of ints as input and run a special sorting algorithm on it. This algorithm must first sort by int frequency, less frequent first, then sort by value. For example ...
8
votes
4answers
3k views

Beginner C++ calculator

I'm relatively new to programming, but am really enjoying it. I have taken a couple of classes but mostly code for fun (for now). I decided to make a program implementing some basic functions, switch ...
3
votes
4answers
97 views

Count combinations of positive and negative that sum to target number

The problem I'm solving is given as follows: You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and <...
1
vote
0answers
35 views

Maximize product of sum of subsequences [closed]

Code Chef Problem description You are given a sequence of \$N\$ powers of an integer \$k\$; let's denote the \$i\$-th of these powers by \$k^{A_i}\$. You should partition this sequence into two ...
0
votes
2answers
48 views

Function that adds commas between groups of 3 digits in a string

My program contains some very large integers and uses the GMP library. The output contains integers (probably small enough to fit into int). I would like to make ...
7
votes
4answers
2k views

Most efficient way to find an entry in a C++ vector

I'm trying to construct an output table containing 80 rows of table status, that could be EMPTY or USED as below ...
0
votes
0answers
49 views

Smart pointers and simple object management system

I am attempting to implement smart pointers to create a fast but relatively bulletproof object management system that allows adding, removing and retrieving objects. I come from a C# background and am ...
0
votes
1answer
73 views

Implementation of a Hash Map in C++

I created a templated Hash Map class in C++, which supports most of the basic C++ types (e.g. int, float, ...
1
vote
1answer
59 views

Addition function for two Big Integers represented as std::string

This function is from my attempt to write a Big Integer class in C++. Below, I have a simple addition function. It takes two strings of arbitrary length which contains only digits (no '-' sign as ...
6
votes
1answer
118 views

Trie Implementation in C++11

I implemented a Trie in C++11, but I am not sure if my usage of struct and std::unique_ptr, and ...
2
votes
0answers
34 views

Rehashing a hash table in c++ with quadratic probing

The code below is my attempt at trying to create a hash table. I'm currently stuck with the rehash function as I think it's not efficient enough (I believe it's O(n^2). I'd be grateful if someone ...
2
votes
1answer
80 views

Filling up a hand with random cards that are not yet drawn - Monte Carlo

I would like to know if there is a more efficient way to speed up below code. This function is meant to fill in a set of poker hand with the remaining cards using Mersenne Twister for a Monte Carlo ...
3
votes
2answers
70 views

Parallel processing simulation

Input n number of workers and m jobs to be scheduled, followed by m lines of time ...
2
votes
0answers
35 views

Iterator that groups elements of its source

I wrote an iterator to access the pixel in an packed image. It works, but it is slow. 1.Are there any mistakes that can be avoided and might lead to better speed? 2.Are there any pitfalls that ...
2
votes
1answer
46 views

Managing different types of morphism and their compositions

Here's some code I wrote to manage the different types of morphism and their compositions in C++17. Let me know if you had any suggestions for substantial simplifications or improvements, or if I ...
3
votes
2answers
77 views

Class to store and manipulate Cartesian coordinates and vectors

I have made a C++ class to manipulate 3D vectors in Cartesian coordinates. However, the performance of my class is much slower (about 2.5x) than simply using something like ...
4
votes
2answers
177 views

Data Structures for Counting Duplicates and using std::vector::erase

Problem Dupe detection for a vector of ints. I simply want a count of the unique input characters that occurred at least twice. The goal is to count a dupe only once and ignore that input character ...
5
votes
2answers
76 views

Tick-tack-toe (Jumping into C++)

The exercise is from Alex Allain's book "Jumping into C++". From Chapter 10 Practical Problem 4: Write a small tic-tac-toe program that allows two players to play tic-tac-toe competitively. ...
2
votes
0answers
51 views

SIMD product of a 4×4 matrix and a vector

I wrote a matrix class for use in a ray tracer. I already have a 'scalar' version up and running, but now I'm trying to rewrite it to use Intel SIMD Instrinsics. I realize my compiler (clang-7.0.0) ...
1
vote
1answer
38 views

linearly interpolate NA values in Rcpp::NumericVector

I am trying to fill missing values with linearly interpolated values in an Rcpp::NumericVector -- leaving in place leading and trailing NA-values. The desired ...
0
votes
1answer
33 views

subclassing standard containers? [closed]

I have read so many times that one should not subclass standard containers. Is there cases that one can subclass them ? for example, I have the following case: ...
1
vote
0answers
26 views

Drawing rectangle on a video with mouse in QT

I created a where I select a video using QOpenFileDialog and play the video on QGraphicsView. After that I select an area on ...
5
votes
2answers
570 views

sorting a map by converting it to vector

I have a map that I want to print out sorted by value, I convert it to vector and sort the vector. Is this code correct? ...
3
votes
1answer
55 views

C++ B+Tree search & insert implementation

I made a B+Tree example for C++. I tested it a lot. I didn't get any errors or mistakes but i can't be sure it is really works (without any bug) or I don't know it is suitable for use (Memory problems,...
0
votes
1answer
68 views

Matrix arithmetic operations

I am currently attempting to implement Matrix Math for another project I am working on. However, I am not sure whether this implementation will work. Can someone please tell me if there are any ...
2
votes
2answers
37 views

Project Euler #4 - Finding the largest palindrome that is the product of two three-digit numbers.

This is my attempt at the 4th problem on Project Euler: ...
6
votes
2answers
60 views

Snake game using SFML CPP

I made using SFML my first game project. It's a snake game, and I used 2 custom classes: snake fruit (snake grow by 1 when eat it) Here's main.cpp code: ...
4
votes
1answer
85 views

Finding decreasing sequences in an array of numbers

Ants Requirement Given a natural number \$n\$, representing the number of days the study is made, and then a number \$x\$ of \$n\$ natural numbers, representing the number of working ant ...
0
votes
1answer
73 views

Functional List in C++ [closed]

This is rather toy example of immutable datatype in C++. I've tried to follow functional languages like Scheme, Racket - making list as a cons cell: list is list or is empty. ...
5
votes
1answer
329 views

C++ grades calculator using pointers

I have a program to calculate grades that uses pointers and I am trying to figure out if I did it right and if there are any problems with my implementation. I'm trying to get a more firm grasp on ...
6
votes
1answer
65 views

Type-safe Euclidean vectors in C++

I'm trying to follow the Raytracing in One Weekend book, and I found that he uses the same Vec3 class for everything - colors, coordinates, direction, and more: <...
3
votes
2answers
92 views

Ring Buffer Implementation in C++14

A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than moving the data. Ring buffers are often used in embedded computer design. ...
3
votes
2answers
49 views

Mockable clock meeting std::chrono TrivialClock requirement and interface

I'm using the time for e.g. ping and timeout calculation as well as animations in a game. So my (big) codebase uses std::chrono::steady_clock::now() in many places. ...