This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Threaded Binary Tree Worked with same code a few days ago under g++ in ubuntu 16.04
- From: nick <xerofoify at gmail dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: GCC help <gcc-help at gcc dot gnu dot org>
- Date: Sun, 27 Nov 2016 17:43:15 -0500
- Subject: Re: Threaded Binary Tree Worked with same code a few days ago under g++ in ubuntu 16.04
- Authentication-results: sourceware.org; auth=none
- References: <1b18bb13-e0d0-2cae-98f2-546d4d22ed4a@gmail.com> <874m2sd25w.fsf@mid.deneb.enyo.de> <dacf14e6-aa2b-9175-7ea0-1c29f81d481d@gmail.com>
On 2016-11-27 05:15 PM, nick wrote:
>
>
> On 2016-11-27 04:48 PM, Florian Weimer wrote:
>> * nick:
>>
>>>> Greetings all, Sorry for the stupid question but I for whatever
>>>> reason can't get this to work and was wondering if it's me being
>>>> stupid or something else.
>> The first step is to fix all compiler warnings:
>>
>> threadedtree.h: In instantiation of ‘ThreadedTree<T>::iterator ThreadedTree<T>::insert(const T&) [with T = int]’:
>> main.cc:6:16: required from here
>> threadedtree.h:282:17: warning: operation on ‘tmp->ThreadedTree<int>::Node::rightThread’ may be undefined [-Wsequence-point]
>> tmp->rightThread = tmp->rightThread = true;
>> ^
>>
>> Then run under valgrind:
>>
>> ==7877== Conditional jump or move depends on uninitialised value(s)
>> ==7877== at 0x400D30: ThreadedTree<int>::printTree() (threadedtree.h:244)
>> ==7877== by 0x400A2B: main (main.cc:8)
>> ==7877== Uninitialised value was created by a heap allocation
>> ==7877== at 0x4C29180: operator new(unsigned long) (vg_replace_malloc.c:324)
>> ==7877== by 0x400BFA: ThreadedTree<int>::insert(int const&) (threadedtree.h:280)
>> ==7877== by 0x400A1F: main (main.cc:7)
>>
>> I have no idea if this points towards the cause of the bug, but it's
>> always worth a try.
> That's work. I have two more questions which make no sense which is both begins create a infinite loop or our not called.
> iterator begin(){
> Node* curr = root_;
> if (curr != nullptr) {
> while(curr->left_!=nullptr){
> curr = curr->left_;
> }
> }
> return iterator(curr);
> }
> Other version is the same but creates a const_iterator. Also wasn't sure if
> if (p->data_ < data){
> tmp->right_ = p->right_;
> tmp->left_ = p;
> p->right_ = tmp;
> p->rightThread = false;
> return iterator(p->right_);
> }
> else{
> tmp->right_ = p;
> tmp->left_ = p->left_;
> p->left_ = tmp;
> p->leftThread = false;
> return iterator(p->left_);
> }
> logic is correct as it seems so. I am not sending this to the list as this is probably my fault :).
> Huge Thanks,
> Nick
>
I already sent this to Florian but was wondering why the above begins are never called as end works fine. I
cannot understand why and it makes no sense logically.
Nick