Hi,
While I am trying to debug the following code , it is executing as expected.
But when trying to run with out debugging (debug version itself) , the
applicaton is crashing. May I know why is it so.
#include <stdio.h>
#include <stdlib.h>
struct Tree {
int data;
int priority;
struct Tree* lChild;
struct Tree* rChild;
};
struct Tree *root = NULL;
struct Tree *prev = NULL;
void heapInsert(struct Tree *tree, int key, int priority){
struct Tree *node = (struct Tree*)malloc(sizeof(struct Tree*));
node->data = key;
node->priority = priority;
node->lChild = NULL;
node->rChild = NULL;
if (root == NULL){
root = node;
} else {
struct Tree *dummy = (struct Tree*)malloc(sizeof(struct Tree*));
dummy = root;
if (dummy->priority <= node->priority){
root = node;
root->lChild = dummy;
}
while (dummy->priority > node->priority){
if (dummy->lChild == NULL){
dummy->lChild = node;
dummy = node;
}
else if (dummy->rChild == NULL) {
dummy->rChild = node;
dummy = node;
}
else {
prev = dummy;
dummy = dummy ->lChild;
}
}
if (prev != NULL){
prev->lChild = node;
node->lChild = dummy;
prev = NULL;
}
/*printf("You are accessing the dummy root with pr %d\n",
dummy->priority);
printf("You are now trying to insert a second node.\n");
printf("First node still with priority %d", root->priority);*/
}
}
void treeTraversal(struct Tree * tree){
printf("Data: %d\n", tree->data);
printf("Priority: %d\n", tree->priority);
printf("LChild points to: %#x\n", tree->lChild);
printf("RChild points to: %#x\n", tree->rChild);
}
int main(void){
struct Tree *p = (struct Tree*)malloc(sizeof(struct Tree));
heapInsert(p,1,10);
heapInsert(p,2,2);
heapInsert(p,3,7);
heapInsert(p,4,9);
heapInsert(p,5,20);
heapInsert(p,6,5);
treeTraversal(root);
return 0;
}
GopiKrishna Komanduri
Software engineer
[EMAIL PROTECTED]
--- On Fri, 28/11/08, Pedro Izecksohn <[EMAIL PROTECTED]> wrote:
From: Pedro Izecksohn <[EMAIL PROTECTED]>
Subject: Re: Res: [c-prog] Re: integer promotions
To: [email protected]
Date: Friday, 28 November, 2008, 6:20 AM
--- Thomas Hruska wrote:
> Try compiling your code as C++ and see if there
> is a difference. C++ compilers tend to generate a lot more warnings as
> the language is, generally-speaking, more strict.
[EMAIL PROTECTED] ~/programming/ c++/problem
$ ls -la
total 10
drwxr-xr-x+ 2 root None 4096 Nov 27 22:47 .
drwxr-xr-x+ 11 root None 4096 Nov 27 22:35 ..
-rw-r--r-- 1 root None 69 Nov 27 22:37 Makefile
-rw-r--r-- 1 root None 261 Nov 27 22:46 problem.cpp
[EMAIL PROTECTED] ~/programming/ c++/problem
$ cat problem.cpp
#include <climits>
#include <iostream>
using namespace std;
int main (void) {
unsigned short int a;
unsigned long long int b, c;
a = USHRT_MAX;
b = (a*a);
c = ((unsigned int)a*(unsigned int)a);
cout << "Why " << hex << b << " != " << c << " ?\n";
return 0;
}
[EMAIL PROTECTED] ~/programming/ c++/problem
$ cat Makefile
problem : problem.cpp
g++ -Wall -Wconversion problem.cpp -o problem
[EMAIL PROTECTED] ~/programming/ c++/problem
$ make
g++ -Wall -Wconversion problem.cpp -o problem
[EMAIL PROTECTED] ~/programming/ c++/problem
$ ./problem.exe
Why fffffffffffe0001 != fffe0001 ?
Add more friends to your messenger and enjoy! Go to
http://messenger.yahoo.com/invite/
[Non-text portions of this message have been removed]