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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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
0answers
2 views

Singleton rewrite based on old one

For some time I'm using this singleton implementation. It was written in 2003 by some programmers who were most likely paid 5 euros per hour. I read that singletones are bad, yet my program uses ...
0
votes
0answers
9 views

Support the parity of the path length / Checking bipartiteness online

I am trying to learn to check for bipartiteness online using Disjoint Set Union. I found one tutorial . But the implementation of code and tutorial in section "Support the parity of the path length / ...
0
votes
1answer
13 views

C++ - Graph implementation for data types other than int

I am learning graphs and most of the implementations that I see are meant for int. So, I decided to code an example that can take other data types such as ...
5
votes
0answers
24 views

Endless stream: stream a range and return default value if the range is exhausted

Introduction: Motivation Sometimes there is a need to merge N > 1 ranges, and they don't have equal length, but there is a value which can be used in case the range is already exhausted. It is ...
4
votes
2answers
48 views

Move friendly merge sort - follow-up

This is a follow up to this question. I'm only interested to see if this is implemented correctly for move-only types. ...
0
votes
0answers
25 views

Excercise from PPP Order class

I did the following two excercise from PPP by Stroustrup: Define an Order class with (customer) name, address, data, and ...
6
votes
4answers
306 views

Add Two Numbers given in Reverse Order from a Linked List

Problem Description You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add ...
10
votes
1answer
46 views

CodeVita challenge: forming the latest valid datetime in a year using some given digits

After answering someone's Code Review question, I decided to tackle a sequel: Given an input consisting of 12 non-decreasing single digits separated by commas, form the latest valid date time in a ...
2
votes
2answers
57 views

Scroll text across a fixed width

In an interview, I was asked to write code to produce this output: T TE TES TEST EST ST T The code I wrote was: ...
1
vote
2answers
46 views

Codility's BinaryGap: Hardware-aware answer [on hold]

This is a well-known question, which some others have posted about on this site. Here's my first shot following a state machine approach: ...
2
votes
0answers
20 views

Hunt the Wumpus GUI (FLTK)

I used the code from the text based hunt the wumpus game discussed here: Text based game “Hunt the Wumpus” Version 3 to create a gui Version based on excercises from PPP by Stroustrup. For the GUI i ...
4
votes
3answers
668 views

Recursion: Count from x until n and backwards

I wrote this recursive function to print a number sequence from x to n and n to x back. Here is one of the ideas I had to improve it, but it didn't work out (use another ternary operator at the end ...
5
votes
2answers
85 views

Circular-shift with variable bitlength

For some memory masking operations I need a bitwise-rotation functionality for unsigned integral types. I came across solutions based on the wiki article, but have not found a variation for a function ...
3
votes
1answer
44 views

Customized lock-free RingBuffer

I have implemented my own lock-free ringbuffer for multiple producers multiple consumers using vector. Can you guys help me review to see if there are any problems and ways to improve? Explanation: ...
7
votes
2answers
109 views

Vector-like type for type that can't be moved or copied

I was in need of a vector-like type that could hold types that couldn't be copied or moved so I implemented one. I tried to make it similar to standard STL containers. Is the use of the macro to ...
12
votes
5answers
1k views

Processing XYZ data from a large file

I'm new to programming (1.5 years experience at university), and I'm working on my first computer vision related project! My goal is to take a file which might have CSV (comma separated) or txt format ...
6
votes
1answer
73 views

C++/SDL2 Tic-Tac-Toe

This is my second attempt at creating a game. I think I have gotten the basic ideas of state machines and game loops down, but I'm sure there are still a lot of things I can learn. It is a basic Tic-...
4
votes
1answer
54 views

A thread safe task queue implementation using my own lock_guard in C++

As an exercise in multithreaded programming, I am trying to implement a basic FIFO task queue. For this, I also implement simplified version of my lock_guard, from ...
1
vote
1answer
28 views

Generic Single Linked List with smart pointers follow up part 3

Okay, this will most likely be the last post I make for Singe Linked List unless significant revision is needed. This post following from here. Shout out to @hoffmale for showing me the ways of the ...
-3
votes
0answers
44 views

Parallel computing [closed]

Measuring the effect of Parallelization Using one of the suggested methods in class ( p-threads, OpenMP, C-Sharp or Java Threads) implement an application that adds two integer vectors (A,B) and store ...
3
votes
1answer
326 views

Simple rwlock implementation in c++11

For answering this question of stackoverflow I have written the code https://stackoverflow.com/questions/12033188/how-would-you-implement-your-own-reader-writer-lock-in-c11 Can someone review it - ...
6
votes
2answers
107 views

C++2a comparison-based topological sort algorithm

Here's my attempt at a C++2a Standard Library–friendly "topological sort" algorithm. There are several areas of interest here: The algorithm is comparison-based and in-place, just like ...
7
votes
3answers
966 views
-2
votes
1answer
48 views

Is this a good/bad/ugly way of assigning unique IDs to objects in C++? [closed]

My project has many different objects from different classes, and I want each object to have a unique ID. IDs should be unique within each class type, but can be the same among different classes. For ...
-5
votes
0answers
33 views

how to create stopwatch for microcontroller atmega328p [closed]

How can I create stopwatch a assembly code for Atmega328p micro controller is there any one providing this code?
-2
votes
1answer
50 views

Appending a newline character to a string [closed]

I'm trying to find a simplest solution to append a newline character to a string. Although the following code works, I would like to know if it's possible to make the code simpler. (The argument ...
-5
votes
0answers
61 views

Readability Vs Efficiency [closed]

Readability Vs Efficiency V1 and V2 are equivalent. V1 is more readable, but V2 saves the call to function_call_2. What should be the ideal choice? V1 ...
8
votes
2answers
144 views

Modern C++ singly linked list

This is a rather minimal (though fully functional) implementation of a singly linked list. It supports \$\mathcal{O}(1)\$ front insertion and deletions, as well as \$\mathcal{O}(1)\$ random insertions ...
1
vote
2answers
61 views

Generic Single Linked List with smart pointers follow up part 2

This is probably the last time I will post this data structure that I have been working on. I have added in an iterator and const_iterator class (although I do not use them probably where I should be)....
-1
votes
0answers
19 views

Create array that fills with series of random numbers, prints the elements of the array and more [closed]

I need to create a C++ program that creates an array, fills the array with a series of random numbers, prints the elements of the array to cout, identifies the largest element in the array and prints ...
8
votes
1answer
281 views

Solve 8-tile sliding puzzle

I created a BFS algorithm in order to solve an 8-puzzle, and while it works, it is awfully slow compared to my DFS implementation. My main point of concern is the puzzleExists() function, which ...
12
votes
7answers
2k views

Longest consecutive sequence of ascending, descending, or equal integers

Given an array of integers, find the longest consecutive sequence, where a sequence is defined as being either (strictly) ascending, (strictly) descending, or all-equal. 836926 then has the longest ...
3
votes
0answers
78 views

Travelling salesman problem using genetic algorithm in C++

I have implemented travelling salesman problem using genetic algorithm. Since project is not so small I will give short introduction. GeneticAlgorithmParameters - ...
7
votes
3answers
99 views

Filter template meta function

I wrote a simple C++ template meta function for filtering out types from a list not matching a predicate. This is similar to Filtering variadic template arguments but does pattern matching instead of <...
1
vote
2answers
56 views

Generic Vector Class using smart_pointers

I have decided to rewrite what I did here, following the suggestions to use smart pointers. I will rewrite the other data structures as well using smart pointers where appropriate. I just want to see ...
4
votes
2answers
112 views

Snake game for Windows text console

I have started to code Snake in C++. I am finding it hard to make progress on this project because the code is quite messy. How can I improve the structure of my program? main.cpp: ...
4
votes
3answers
87 views

Iteration over “zipped” tuples (for_each_in_tuples)

I want to implement for_each_in_tuples that takes a functor and one or more tuples of the same size and applies this functor to <...
3
votes
2answers
72 views

Disassembler for intel 8080 v2

As many suggestions were given for the code I posted here, I decided to show you the new version for review. I Removed the OpenCatalog class, ...
5
votes
0answers
44 views

Resource cache based on Stroustrup 22.2.4

I recently read "The C++ programming language" chapter 22 and I thought the example given in chapter 22.2.4 was quite interesting. I thought it should be possible to make this system caching, so it ...
2
votes
4answers
122 views

Generic Single Linked List Using Smart Pointers Follow up

I am extending this post following from here. I made some of the changes that I could make in the previous post. Although, I have not been successful in creating iterators for my class. The reason ...
1
vote
3answers
73 views

Stack implemented with linked list

I have looked at some previous posts and changed my code accordingly. Do you have some suggestions about my current code? Here are my specific questions: What should ...
11
votes
3answers
1k views

Multithread to print odd and even numbers

I recently started on C++ multithreading. Here is my code to print odd and even numbers in two different thread. Can somebody please review this code? ...
4
votes
4answers
361 views

Initialized Array Template Class (C++)

The problem We want to use a very large array for some computations. When created, all the elements of this array have to be initialized to some value. We'll only use a few values from the array1,...
3
votes
2answers
67 views

First Swing at an AVL Tree Implementation in C++

I've implemented a simple AVL binary search tree. For no real reason I decided to implement this without multiplicity, so if we try to insert(5) twice, it's only stored once in the tree. I've also ...
6
votes
2answers
97 views

Phone book program using hash table in C++

I am a student and I am implementing data structures concept by myself using C and C++. I have implemented the concept of hash table here by making a "Phone book" program that takes input which ...
10
votes
2answers
127 views

Disassembler for intel 8080

I have written a disassembler for Intel 8080, able to translate binaries into opcodes and parameters. Sorry for posting so much code, but everything posted here is useful for the understanding of the ...
0
votes
1answer
58 views

Scanning the subnet by ip range

By applying the get_name and get_mac functions to the specified IP address, it is possible to estimate the network availability ...
5
votes
4answers
137 views

Generic Single Linked List using smart pointers

I have decided to rewrite what I did here, following the suggestions to use smart pointers. I will rewrite the other data structures as well using smart pointers where appropriate. I just want to ...
1
vote
0answers
28 views

A simple and efficient packet frame encoder/decoder

I have written a simple packet-framing class, for converting un-encoded 'packets' into encoded/delimited 'frames,' to be sent over a P2P serial connection. The functionality is based on the RFC 1662 "...
5
votes
2answers
59 views

Iterable object on set of ids

For some of the algorithms that I am implementing it turned out to be useful storing ids in order to iterate on objects, while also avoiding having to think about reallocation and invalidation of ...