I've been working on my deletion function for Red and Black trees but can't seem to get it to work. From what I can tell, the remove function, instead of deleting the single value that will my prompt by the user, will delete all the values that are in the red and black tree.
Code: bool RedBlackTree::remove(int x) { if(!search(x)){ return false; } else { Node* z = new Node(x); rbremove(z);
I have a doubly linked list from which I need to occasionally delete elements (any elements that have a type value different from 0). The function I have seems to work, but looking at it, I think I could probably make the logic cleaner.
The structs in questions are declared here, with irrelevent variabled omitted:
A few months ago I wrote a simple neural network using back propagation algorithm. It's input is a 2D array of any given size and type. I tried to make it learn the logic functions like AND & OR it worked. So now I want to try image recognition and I need the image as a 2D array of RGB values.(I mean three arrays of course one 2D array for each color.)
How can I get an array of RGB from an image? Can I do it with streams?
Write a program that has an array of at least 20 integers. It should call a function that uses the linear search algorithm to locate one of the values. The function should keep a count of the number of comparisons it makes until it finds the value. The program then should call a function that uses the binary search algorithm to locate the same value. It should also keep count of the number of comparisons it makes. Display these values on the screen.
/* search benchmark.cpp this program searchs through a array of 20 integers */
#include <iostream> #include <string> #include <iomanip> using namespace std; int array [20]; int count;
My program generates an array of random numbers. I want to then search a specific number within the array. If the number is in the array then a message apopears on the console saying that its there. I'm using the binary search algorithm to do this.
#include <iostream> #include <ctime> #include <cstdlib> #include <iomanip> #include <cstring> using namespace std; int size; int getSize() { return size; }
This program is sorting a randomized array of integers using the bubblesort algorithm.
I am trying to modify n correct the source code,so that the swapping of two values will be done by a function called swap values() by using call-by-reference but function should have as arguments only the two array elements that must be exchanged. (Note: do not pass the whole array to the function!) .We consider an array with the first element containing the number of elements in the array, followed by 10 randomly initialized integers (elements).
The code must sort the 10 elements in ascending order.
Compile: g++ -Wall sorting.cpp -o sorting */ #include <iostream> #include <stdlib.h> using namespace std; int main() { const int SIZE=10;
I have an algorithm which uses nested for loops, which looks for duplicate elements in an array. However, as soon as one duplicate element is found... the program will stop looking for more duplicates? My program continues to look for more even though one is found? I know there is a break command but I can't get it to work. Code is below:
output of program: Repeating element found first was: 2, 1
Although I want the outcome to be; Repeating element found first was: 2
#include<stdio.h> #include<stdlib.h> #include <iostream> using namespace std; void printRepeating(int arr[], int size) { int i, j;
I am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.
The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:
Code: #define EMPTY 0 #define X 1 #define O 2 Here is my function: Code: int check_state(int board[3][3]) { int winner = 0;
A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).
Example: Desired numerical combinations from integers 1 to 3:
And so on until the nth length (in my case a length of 12).
First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.
I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.
Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.
I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.
I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different.Here they are:
I have VRP algorithm written in C++, run with command prompt Windows. input (command line) -> VRP.exe -> output (txt file)
Now I want to built a website to run it as SaaS. How to run an exe application(compiled c++) in server used as Saas? What kind of programming do I have to use? Ruby or html5 or others? I don't know how to start.
To construct and write down algorithm of determination of the sum of squares of consecutive integers with recursion use. I tried to do something:
public static int RecSumSquare(int x, int n) { if (n < 0) throw new ArgumentException("n should be greater than zero"); if (n == 0) return 0; else return x*x+RecSumSquare(x, n - 1); }
But I don't know as the beginning and the end of this algorithm will look.
I'm still a beginner at C++ programming, I have tried to implement some optimization algorithms (related to database) in C++, I cannot say it is going as far as I thought it will be, some errors does not even make sense, I will cut to the chase, I need to implement SA (Simulated Annealing) in C++, SA, which is an example of the Randomized Algorithms, functions on the concept of randomness and probability. In addition, I searched the internet with no (let say "accurate") code that might give me insight on how to begin, I only found one code for SA that I could understand, and edited it (which will be shown below), still looking to enhance and correct it more.
If the concept of Simulated Annealing is not clear, you may refer to the following papers which can be found in a simple Google search: Simulated Annealing Algorithms: an overview.An Introduction to Interacting Simulated Annealing. Query Optimization (there is a sub-section for Simulated Annealing in this paper that explains SA briefly) ....
write an algorithm using stack to determine if an input of string is in the form xCy where y is the reverse of x.x and y are strings of A and B. eg : AABACABAA
I'm trying to implement the flocking algorithm in C++. I've tried to implement it myself by making all the particles 'home-in' on the player. When 2 particles then collide within their larger bounding boxes they home-in to each other. And when the 2 particles are actually touching they repel each other until they are outside of their bounding boxes and find another particle to home-into.when I run my application the particles all home into the player and come to a stand still along the Y-axis above the player.
All the particles in question are stored in a Vector, with a pos and velocity.
for(int i = 0; i < swarm.size(); i++) { for (int j = 0; j < swarm.size(); j++) { if (swarm.at(i)->getParticleModel()->getPosition().x < gameObjects.front()->getParticleModel()->getPosition().x) { if (swarm.at(i)->getParticleModel()->getTouching() == false)
I made this program in C++ that should, by a genetic algorithm, build a word identical to the initial one improving itself recursively.
The code is:
main.cpp #include <stdio.h> #include <cstdlib> #include "Genetic.h" using namespace std;
[Code] ....
The problem is: when running with gdb it gave me this
warning: Could not load shared library symbols for linux-vdso.so.1. Do you need "set solib-search-path" or "set sysroot"? CREATA LA PRIMA POPOLAZIONE PARTE L'EVOLUZIONE TROVATO BEST: fzlrq TROVATO BEST: hglhe
Program received signal SIGSEGV, Segmentation fault. 0x000000000040720e in Genetic::Gene::Gene (this=0x7fffff7ff030) at Genetic.h:20 20 struct Gene {
The line corresponds to the struct declaration. Every 1000 executions it runs well.
I am looking for a compression algorithm which compress sequence of random numbers (will be in sorted order but some of the numbers may be missing). The compressed data will be sent to other component where decompression will take place.