C++ :: Simple Tree But Pointers Changing Themselves

Apr 6, 2014

The code meant to generate a simple tree. As you can see from the output, somewhere the parent pointers get messed up. And yet, I can't seem to find where, and if I output them in the constructor (only time they get modified) they all look OK. When I run output_path_to_root() on any grandchildren of the root I get a segmentation fault. How the parents are getting messed up? I was wondering if my vectors changing size is causing pointers to shift around but I'm not sure.

//tree.cpp

#include <iostream>
#include <vector>
using namespace std;
struct A {
int n;
vector<A> get_children() {

[Code] .....

12 ( )
6 ( parent->node.n: 12)
3 ( parent->node.n: -1487162336)
1 ( parent->node.n: -1429198496)
2 ( parent->node.n: -1487162336)
1 ( parent->node.n: -1429198496)
4 ( parent->node.n: 12)
2 ( parent->node.n: -1487162336)
1 ( parent->node.n: -1429198496)

View 1 Replies


ADVERTISEMENT

C++ :: Create Simple Payroll Management Application Using Concept Of Binary Tree?

Apr 2, 2013

Create an a simple Payroll Management Application using the concept of Binary Tree. The program will allow you to add, sort, view, search record. The application have also the capability to save and retrieve data in a file.

View 1 Replies View Related

C/C++ :: Implementing Tree From Array - Use Of Pointers?

Jan 23, 2015

I'm trying to implement a tree from an array an first I used add_left_node() and add_right_node methods (as requested in the problem I have). But I'm a bit confused about the use of pointers in this. Is using &node the same as defining *pointer=node and then using "pointer" in place of &node?

I get only the value of the first node I created. For the node's left and right values I get long numbers displayed, so I think I have interfered with the addresses.

This is my main method:-

int main(){
bintree_node q = bintree_node(1);
bintree_node *poin=NULL;
poin = &q;
add_left_child(poin, 5);
add_right_child(poin, 6);

[Code] ....

View 6 Replies View Related

C++ :: Changing Integer Into New Integer With Simple Mathematical Operations?

Jun 15, 2014

changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).

View 4 Replies View Related

C :: Inserting Element In Binary Tree Using Pointers

Sep 7, 2014

I want to insert an element into binary tree using pointer passing through functions. In my program i have used three structure which are follows :-

Code:

struct tree{
int data1;
struct tree *leftptr;
struct tree *rightptr;
};
struct list{
struct tree **data;
struct list *node;

[Code]...

Here i think problem is in allocating memory to n2 . why i do this because i want to store the address of address of left and right pointers of tree and extract that address to get the address of left and right pointers. Is my method correct ?

View 2 Replies View Related

C/C++ :: Find Maximum Element From A Tree (not A Binary Tree)

Oct 31, 2014

I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...

View 1 Replies View Related

C++ :: Create Binary Search Tree Template To Be Used To Create AVL Tree

Feb 10, 2013

For my data-structures class, I am attempting to create a binary search tree template to be used to create an AVL tree. I've written a Generic_Tree template for the BST to inherit from, and before I jump into implementing the AVL tree I'm testing the BST member functions. Everything was compiling fine until I added the BST insert() function. Now, I'm getting the following error message from my linker:

undefined reference to 'BST<void>::insert(int, void*)'

Stemming from the call in main line 16.

my makefile compiles with:
g++ -Wall -g Generic_Tree.cpp BST.cpp barfing.cpp main.cpp

Generic_Tree:

template < typename NODE_DATA, unsigned MAX_KIDS >
class Tree {
protected:
struct NODE {
NODE_DATA* contents;
Tree* child[MAX_KIDS];
Tree* parent;

[Code] ....

I'm use to c and havn't used classes or templates before (except for declaring instances of them). The whole syntax is mystifying to me,.

View 4 Replies View Related

C :: Create Array Of Pointers To Pointers Which Will Point To Array Of Pointers

Feb 28, 2014

I'm trying to create an array of pointers to pointers which will point to array of pointers (to strings) I tried

Code:

int i;
char *string[]={
"my name is dave",
"we like to dance together",
"sunny day",
"hello",

[code]...

the app keeps crashing , I don't know how to make the array-elements to point to another array-elements..

View 4 Replies View Related

C++ :: Comparing Char Pointers To Integer Pointers

May 21, 2013

I am a little confused while comparing char pointers to integer pointers. Here is the problem:

Consider the following statement;
char *ptr = "Hello";
char cArr[] = "Hello";

When I do cout << ptr; it prints Hello, same is the case with the statement
cout << cArr;

As ptr and cArr are pointers, they should print addresses rather than contents, but if I have an interger array i.e.
int iArr[] = {1, 2, 3};

If I cout << iArr; it displays the expected result(i.e. prints address) but pointers to character array while outputting doesn't show the address but shows the contents, Why??

View 2 Replies View Related

C++ :: Changing The Value Of A String?

Dec 17, 2013

If I was to input for example 'x' into my program, how could I change that to something like 'HuS581' every time that specific character was inputted?

View 2 Replies View Related

C :: Changing The Value Of Something From A Function

Oct 30, 2013

I was talking to someone earlier about how to change the value of something from a function, and they said what was needed was to use a ** to change something, and was wondering if I could get a walk - through of what happens. I understand a single pointer well enough, but a pointer through a pointer is kind of confusing to me. Here is a simple example.

Code:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int add(int ** TOP, int * stack);

int *stack = NULL;

[Code] ....

Why is it that when the program prints the address of TOP in main, it is different than the address of TOP in the function? Is it because it is a different instance of TOP because it is in the function? When I put the number on *TOP, and come out of the function back to main, it then says the address of TOP is the number entered into *TOP, and am not sure why. And the **TOP ++ at the end I am thinking it increments malloc by 1, therefore bringing the pointer TOP up to point at the next element, or am I completely off base there?

View 7 Replies View Related

C++ :: Changing Const Int Value?

Nov 7, 2013

#include <iostream>
#include <iomanip>
using namespace std;

// cin.get() <-------------- used to let the user read the screen

// Function prototypes
void calcSales(const int [], const double [], double [], int);
void showOrder(const double [], const int [], int);

[Code] ....

How can i change the "const int NUM_PRODS = 12;" from saying id 1, id 2, id 3, etc. to custom product numbers?

View 1 Replies View Related

C++ :: Changing Some Bit Of A Number

Jan 1, 2015

I use miracle library to work with big numbers. I defined a number for example X with 192 bit. at first X= 0 ;I want to change for example 3 bit of it to 1 randomly.as a example:

assume that X has 10 bit :
X=0000000000
random numbers should be :
1000010001
1010100000
1100000100

View 1 Replies View Related

C/C++ :: Changing Complexity From O(n) To O(1)

May 5, 2012

For the following code :

 s = 0 ;
 for(i=m ; i<=(2*n-1) ; i+=m) {
            if(i<=n+1)
            { s+=(i-1)/2 ; }
           else
            { s+=(2*n-i+1)/2 ; }  
      }  

I want to change the complexity of the code from O(n) to O(1) . So I wanted to eliminate the for loop . But as the sum "s" stores values like (i-1)/2 or (2*n-i+1)/2 so eliminating the loop involves tedious calculation of floor value of each (i-1)/2 or (2*n-i+1)/2 . It became very difficult for me to do so as I might have derived the wrong formula in sums of floors . Need Changing complexity from O(n) to O(1). Is there any other way to reduce the complexity ? If yes ... then how ?

View 3 Replies View Related

C++ :: Changing From BigInteger To GMP?

May 15, 2012

I have this code which previously used the BigInteger library, however now I have GMP installed and I want to use that instead.

I have read the manual but I cannot figure out how to use GMP in this function without getting errors.

Here is the function:

Code:
int lucas(long p){ //p is a number in the range of 2 up to 50,000,000, possibly bigger
int s = 4; //previously assigned as a big integer
int z; //used in the for loop below
int M = 2; //previously assigned as a big integer
for(z = 1; z < p; z++){ //this accomplishes the same as 2 to the power of p, and is stored in M
M *= 2;
}
M--;

[code]....

I can initialize variables using the gmp library, but when I'm trying to use the mpz_pow_ui() function I get errors because it wants me to use long integers, which are too small for the numbers I want to work with.

How can I re-write this function to use GMP?

View 4 Replies View Related

C :: Changing Value Of A String Through A Pointer

Jun 11, 2013

Basically, I have a pointer to a C string:

Code: char **objectData and a C string:

Code: char temp[350]; I need to assign the CONTENTS of the temp to the CONTENTS to which objectData points.

Code: *objectData = temp; //this changes the pointer. When temp is deleted, objectData points to some rubbish

**objectData = *temp; //this doesn't seem to be doing anything - the string to which objectData points does not change.

View 3 Replies View Related

C :: Changing Program To Application?

Aug 22, 2014

I was wondering if there was a possible way to change my c program into an application so that i can send the application to another person and not let the other person have access to my codings?

My reasons for asking this question: For the application i want to send there are secrets that are meant to be unraveled by gameplay but i dont want people to look at the codes and know everything.

View 6 Replies View Related

C++ :: How To Get Numbers In Order But Not Changing Name It Goes With

Mar 13, 2014

SO lets say I have a file that says

10 tennent
9 Eccleston
12 Capaldi
11 Smith

How do I get the number's in order but not changing the name it goes with? SO here is how I started it

# include <iostream>
# include <fstream>
# include <sstream>
# include <set>
# include <list>
# include <string>
# include <cctype>
# include <vector>

[Code] ....

View 12 Replies View Related

C++ :: Changing Array Values

Jun 15, 2013

If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?

#include <iostream>
#include <math.h>
#include<iomanip>
#include <vector>
using namespace std;

[code]...

View 7 Replies View Related

C++ :: Changing Variable In For Loop

Apr 28, 2013

I have a problem with my code which I can't work out:

double Mi = 200*pow(10,30);
cout << "
Enter accreted mass increment in solar masses
";
cin >> dm;
cout << "

[Code] ....

Basically the loop works, but gives the wrong results.

I need, at the end of the loop, to sort of "redefine" Mi as "Mi + Macc". I then need it to repeat the loop, and at the end add another Macc so that Mi becomes "Mi + Macc + Macc", etc.

View 5 Replies View Related

C++ :: Changing String To Bool?

Jan 21, 2015

I want to change string to bool but I'm having trouble doing this.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int check_Pythag(int DIMA, int DIMB, int DIMC) {

[Code] ....

View 2 Replies View Related

C++ :: SFML 2.0 Changing Alpha?

Sep 18, 2013

I want to change the alpha of a sprite without changing any other colours

View 4 Replies View Related

C# :: Changing Focus Using Program PID

Apr 17, 2014

For the past couple days I've been making small improvements on a program I made to keep track of a battle count while playing a game. Mainly to reduce the chore of keeping track yourself while you're playing. But it still becomes a hassle to switch back and forth between the program and your game and I was hoping to be able to set focus to the game after the BattleCount method is called.

Currently I am importing a DLL that somebody recommended I use to make a ActiveProcess method that accepts a integer as a parameter which would set the PID but it doesn't seem to be working. The two methods are as follows.

private void countDownClick(object sender, RoutedEventArgs e) {
//Calls a method within my class that subtracts and adds battle values.
counter.CalculateBattles();

//These two change text on my WPF forms with accessor values from my class.
battlesWonText.Text = counter.BattlesWon.ToString();
battlesLeftText.Text = counter.BattlesLeft.ToString();

[Code] ....

This is the C++ code they told me to use to set focus to another application using a PID.

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
const UInt32 SWP_SHOWWINDOW = 0x0040;

[Code] ....

I'm simply trying to figure out how to set focus to a foreign program using their PID and a button click event in WPF. I'm using Visual Studio 2012 on Windows 7.

View 4 Replies View Related

C# :: Changing Database Values?

Dec 14, 2014

I'm working on a project where we access a tiny premade database in order to log into and access another page. I got the log in part working right, but the last part of the project asks me to lock out the account after a certain number of failed attempts. I'm not sure if I need a method to do this or if I can do it right there in the button handler. I tried creating a method to use on the object that was already there, but I'm not sure if that's the right way to go about it. It says it locks the account, but the value in the database never changes, and I don't know why.

//from the login button handler
protected void btnLogin_Click(object sender, EventArgs e) {
bool IsFound = false;
clsDataLayer dl = new clsDataLayer();
IsFound = dl.GetUser(Server.MapPath("~/AddressBook.mdb"), txtUserID.Text, txtPassword.Text);
if (IsFound) {
Response.Redirect("~/frmUpdateAddress.aspx");

[code]....

View 14 Replies View Related

C# :: Changing IP Address On Controller LED

Jul 2, 2014

I have a C-Power5200 driver. I want using the C# language change to the controller's IP address.

Here a link to the website and API.C-POWER 5200

In Annex API controller.

View 7 Replies View Related

Visual C++ :: Changing Code From TCP To UDP

Mar 20, 2013

i had created a client server program in MFC using TCP but by doing this the server can only work on one computer because you have to tell the client the ip address to connect to i.e

Code:
ServerAddr.sin_addr.s_addr = inet_addr("10.13.31.112");

so i want to change my code so that i can use broadcasting but i found out that it only works using UDP. I tried changing the code but the error message "error with sendto: 10047" displays when i run the program.

that error means

Address family not supported by protocol family. An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.

here is the code from server:

Code:
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
int port = 7171;
if (param)
port = reinterpret_cast<short>(param);

[code]....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved