C++ :: How To Linearize A Complex Non-uniform Tree
Oct 25, 2013
I have a tree structure that works likes this.
Each node (if its a 'normal' node) can have 2, 3 or 4 children. I know how to linearize a normal quadtree though it is not memory efficient in this case as the linearization only works for full trees. I'm okay with holes though.
But my tree is slightly odd in that it has non-normal nodes. For example, two leaves will point to a 'dead' node and that dead node has 3 children. Sometimes, 3 leaves will point to a dead node and that dead node will have 2 children. Sometimes, 4 leaves will point to a dead node and that dead node will have 4 children.
So normally, a node will only have one parent and multiple children or it'll just be a leaf. But there are dead nodes that can have 2, 3, or 4 parents and will subsequently have 3, 2 or 4 children respectively.
This is for point location within a Delaunay triangulation and operates off of the idea of volume spanning.
What I abstracted in my code is a 2-to-3, 3-to-2 and 4-to-4 flip. The idea is ,we take 2 tetrahedra and replace them with 3 good tetrahedra but they span the same volume which is good for point location.
As of now, the code that I have works fine. It triangulates tetrahedra and repairs them accordingly but for certain inserts, the search algorithm takes incredibly long and I'm trying to fix that.
I figured a linear structure would be a good attempt so how to linearize a tree that behaves almost polymorphically.
View 4 Replies
ADVERTISEMENT
Jul 31, 2013
I am a bit lost as I am new to C++ and programming in general.
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
ofstream myfile;
[Code] ....
msi
1247
1248
1249
1250
1251
285216ms delay
2853
2854
2855
2856
in the csv file, as above, after every 12 to 13 increment of i there is a skip of 15ms to 16ms. I do not understand why the ms is not a uniform increment. Is there another way I can get a uniform increment of ms?
View 3 Replies
View Related
Dec 28, 2013
How do you randomly select a uniform value from a range of numbers?
View 1 Replies
View Related
Aug 20, 2014
Given a random number generator to generate a number between [0,N), how to prove this number is uniform distributed.
View 1 Replies
View Related
Oct 31, 2014
I want to find maximum element from a tree (not a binary tree ) ???? ...using c language...
View 1 Replies
View Related
Apr 17, 2013
I am trying to write a class that can multiply complex numbers but without overloading operators
View 1 Replies
View Related
Jan 2, 2014
I have some complex declarations to simplify with typedef I have done a try
1. Code:
char (*x[10]) (int);
/* typedef char FUNC(int);
typedef FUNC *FUNC_PTR;
FUNC_PTR x[10]; */ Why we don't use * symbol in the last statement in front of FUNC_PTR?
2. Code:
int (*x(int))[5] I can't do this :/
3. Code:
float *(*x(void))(int);
/* typedef float *FUNC(int);
FUNC *x(void); */
View 7 Replies
View Related
Feb 7, 2015
I'm not sure if I was some weird syntax problem or the way Ive ordered things. But a conditional statement I have created is not performing the way I want it to.
else if ( !( xDif == -1 && yDif == 1 && prevXDif == 1 && prevYDif == 0 ) )
{
foundArr[lastX][lastY] = 1;
}
When debugging, the condition was activated with the values:
xDif = -1
yDif = 1
prevXDif = -1
prevYDif = 0
However, I want the condition not to follow through as I am using the 'NOT' or '!' operator to negative the entire statement. For some reason, the line of code within the else if is still running.
View 2 Replies
View Related
Jul 14, 2013
I have a program written to add 2 complex numbers. Everything is working, except when the sum gets written, it gives me a number that is way off.
#include <iostream>
#include <complex>
#include <fstream>
#include <cstdlib>
#include <math.h>
class complex {
public:
complex();
complex(double r, double i){
[Code] .....
And my output ends up being Enter a complex number (a+bi) :
1+2i
Enter a complex number (a+bi) :
2+3i
x 1+2i
y 2+3i
4.8784e-270+4.85593e-270i
View 12 Replies
View Related
Mar 12, 2014
the only problem I have is where to add
want to play again? y
OK, I am thinking of a number. Try to guess it.
Your guess?
...
want to play again? no
Goodbye
Code :
#include <stdio.h>
#define TARGET 23
#define LOW 1
#define HIGH 100
#define TRUE 1
#define FALSE 0
#define GUESS 6
int process( int guess, int target );
[Code] ....
View 1 Replies
View Related
Mar 18, 2015
//complxCalc.cpp//
#include "complx.h"
using namespace std;
ifstream infile ("in.dat");
int main() {
int i = 0;
complx tempComplx;
double d = 4.5;
[Code] ....
//in.dat//
(4,4) (6,7) (2.5, 9.3) (3,8.4) (13, 26.5) (2.2, 3.4)
My plan is to make this a menu driven program, I have already got the program to give the answers but now I want it to give the user choices as well. The first step in this project is to add a menu to the program. The first menu the user sees should ask the user if the program will be taking input from a file or from the user directly via the keyboard. Regardless of option chosen, the user should then be prompted to specify whether a multiplication,subtraction or addition operation should be performed.
If the user originally chose the file input method then the program should proceed to display to the screen the results of those operations on each pair of data elements in the file and terminate. If the user chose to input via the keyboard then the user should be prompted to input the two numbers, perform the operation on those two numbers and display the results to the screen and ask the user which mathematical operation they would like to do next and continue in this manner until the user chooses to exit the program via a menu option. Fortunately the only file that needs to be edited are in.dat and complxcalc.cpp files.
View 1 Replies
View Related
Feb 28, 2013
Below is a code that is used to calculate complex numbers (a+bi, where i = sqroot (-1)) through multiplication and addition.
However, on my output file, no Header is being printed; the only thing that is being printed is "8 + 7i + = "
"complex.h" is included at the end of the code.
Code:
// Trey Brumley// CMPS
// Dr. Tina Johnson
// March 1, 2013
// Program 2: Classes
// This program will demonstrate the use of classes by using a custom "complex-number" (a+bi) class.
[Code] ......
View 4 Replies
View Related
Feb 26, 2015
1 create a struct called complex which reprensts a complex number . both the real and imaginary compoents should be represented as doubles . ( 1 marks) .
2 write down a function called magnitude which has one parameter ( a struc complex) and a return type of double . it should return the maginude of the given parameter . ( 3marks) .
3 write a function called find_largest which has two parameter (one of type struct complex const * and the other type int) and a return type of struc complex . the two parameter represent an array of complex numbers and number of elements in that array . the function should return elements from array which has largest magnitude . this fucntion must called the magnitude function . ( 5 marks)
4 write a main function . your main fucntion . Your main fucntion should repeately prompt the user for complex number , storing them in an array. you should continuing reading in complex number until the user enters in both componets , at this point you should stop . you should not make an assumptions how many complex number the user will enter , ( i.e use realloc) after reading in complex numbers from the user you should print out real and imaginary components of the complex number with the largest magnitude.
Code:
#include<stdio.h>
struct complex {
double real;
double imag;
[code]....
View 5 Replies
View Related
May 29, 2013
Write c/c++ code of overloading ^operator in complex number class.
If we have two objects of complex number class as fellows,complex obj3 =obj1 ^obj2 ;
Obj3 reak and imaginary pars will be ,
Obj3.real = (obj1.real)obj2.real
And
obj3.img = (obj1.img)obj2.img
View 1 Replies
View Related
Oct 25, 2013
you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]
implement it and the client code to see it rune for the following complex numbers:
c1=3.0-4i,c2=8+4i
i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h
complex.cpp is as follows
#include <iostream>
using namespace std;
class ComplexNumber {
private:
double real;
double image;
[code]....
View 4 Replies
View Related
Mar 6, 2014
I am trying to use std::sort to sort a vector of complex objects using a custom function. However, it keeps erroring "Unresolved overloaded function type".
encounter::encounter(){
// ... cut
std::sort (allpeople.begin(), allpeople.end(), sortByInit);}
bool encounter::sortByInit (character& a, character& b) {
if (a.getinit () == b.getinit ()) {
[Code] ....
View 6 Replies
View Related
Jan 12, 2015
1.What would regex pattern look like for addition of integers?
2.What would regex pattern look like for subtraction of complex numbers?
View 1 Replies
View Related
Aug 13, 2013
I created an algorithm that uses imaginary numbers. It is fine on Dev C++, and now I am trying to port to VS2008. I figured out most things, including how to declare complex numbers. However, I've been having an incredible hard time trying to figure how to use the " i " number! For example:
In Dev C++:
Code:
z_cmplx = cexp(I * f1/Fs * 2 * PI);
Where "I" is a macro from the library!
In VS2008:
Code:
z_cmplx = std::exp(I * f1/Fs * 2 * PI);
Although I DID include <complex> library just like I did before, the compiler gives me: error C2065: 'I' : undeclared identifier.
View 10 Replies
View Related
Jun 30, 2013
I wrote a simple Complex Class and overload input/output and +/- Operators in it!But there is something that doesn't work correctly!I can print an object of that class but I can't print sum of two object or something like that!
Code:
#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
using namespace std;
class Complex {
friend ostream & operator<<(ostream &, const Complex &);
[Code] .....
cout << c3 is Working fine But cout << c1 + c2 is not giving me correct output!
View 3 Replies
View Related
Sep 18, 2012
I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.
Enter operand1: 3 4
operand1: (3, 4)
Enter operation : +
Enter operand2: 1 2
(3, 4) + (1, 2) = (4, 6)
My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.
View 4 Replies
View Related
Apr 10, 2015
This code is meant to open a file and use overloaded operators for a complex number class. I am getting a lot of errors in my class declaration/definition but I am not sure why.
#include <iostream>
#include <cmath>
#include <fstream>
class CN {
public:
double real;
double im;
[Code] ....
View 5 Replies
View Related
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
Dec 17, 2014
I'm trying to implement a T9 (predective text) project in c++ using k-ary Tree.
I would like to understand how can I add the words in the Tree and how can I display them later.
inside each node of the tree I have a linked list (for the words) and a vector of pointers to access the next node
Here are my structs :
struct NodeList{
string data;
NodeList * next;
};
struct List{
NodeList *head;
[code].....
View 1 Replies
View Related
Feb 1, 2014
It only prints out the root in an infinite loop.
Code: void Btree::printTree(Node* tree)
{
tree=root;
if (tree != NULL)
{
std::cout<<" "<< tree->key;
printTree(tree->left);
printTree(tree->right);
}
}
View 5 Replies
View Related
Aug 12, 2014
It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.
Code:
void tree::search(int key,Node* leaf) {
if (leaf == NULL) {
std::cout<<"The tree is empty
[Code] ......
View 3 Replies
View Related
May 28, 2013
I have a problem with the C code . I created two functions, one that runs through the tree inorder, the other that returns the maximum value in the tree. The problem is when I use in the main the method "max", which goes in a loop and not print anything on the screen . If I remove the call to method "max" it works fine. Here's the code:
Code:
#include<stdio.h>
#include<stdlib.h>
#define bool int
/* A binary tree tNode has data, pointer to left child
and a pointer to right child */
struct tNode {
[Code]...
View 13 Replies
View Related