Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Steve Thompson <stevet810@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: primitive instruction for programming |
| Date | 2015-04-14 19:51 +0000 |
| Organization | Friends of the Galactic Collective |
| Message-ID | <j9XI52.bOF.jzi8P@gmail.com> (permalink) |
| References | (2 earlier) <cdd18dd0-0c8b-4904-9590-daedd0bdaa39@googlegroups.com> <mgg66h$u4r$1@dont-email.me> <hLTsJW.t1p.ffTNE@gmail.com> <jrioial433guotc7tj6vm0ie8cd5imd96m@4ax.com> <dfkoia9fjlkq1n91ris88m5n9d5pssog0c@4ax.com> |
On Mon, Apr 13, 2015 at 06:33:38PM -0500, Robert Wessel wrote:
> On Mon, 13 Apr 2015 18:20:38 -0500, Robert Wessel
> <robertwessel2@yahoo.com> wrote:
>
> Code in haste, repent in leisure....
>
> You have to actually put the root node on the stack in there
> somewhere, with something like a:
>
> push (traverse, rootnode);
>
> before the loop.
So, your code should then look like:
> node = rootnode;
> push (end, NULL);
> push (traverse, rootnode);
>
> for(;;)
> {
> pop item
> if (item.type == end) break;
> if (item.type == traverse)
> {
> if (item.node != NULL)
> {
> push (traverse, item.node->right);
> push (output, item.node);
> push (traverse, item.node->left);
> }
> }
> if (item.type == output)
> output item.node;
> }
I can sort of see how that works, although your push and pop macro/
functions are not so clear but that is only a detail. I ought to have
implied that I merely had difficulty generating the algorithm without
gotos, as I have succeeded with (simplified):
p = tree->root;
l1:
if(p->left) {
push(p, LEFT);
p = p->left;
goto l1;
}
l2:
do_something_to(p);
if(p->right) {
push(p, RIGHT);
p = p->right;
goto l1;
}
l3:
if(p == tree->root)
goto next:
pop(p, dir);
if(dir == LEFT)
goto l2;
else
goto l3;
next:
... which is reasonably straightforward but is bound to provoke people
who unconditionally dislike goto. GCC allows one to take the address
of a label and so one can do something like the following:
void *addr;
p = tree->root;
l1:
if(p->left) {
push(p, &l2);
p = p->left;
goto l1;
}
l2:
do_something_to(p);
if(p->right) {
push(p, &l3);
p = p->right;
goto l1;
}
l3:
if(p == tree->root)
goto next:
pop(p, addr);
goto *addr;
But the above reduces portability so I just use an int and the
comparison as in the first example. The hard pard was finessing GCC
to allow using the processor stack as opposed to a stack-like
structure.
Regards,
Steve Thompson
--
"If I had a nickel for every time some idiot called me about a
computer problem that turned out to be user error, I would be able to
retire and spend the rest of my days cultivating clues in my backyard
hillside garden." -- MysteryDog in 24hoursupport.helpdesk.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 00:56 -0700
Re: primitive instruction for programming Richard Heathfield <rjh@cpax.org.uk> - 2015-04-13 09:24 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 01:59 -0700
Re: primitive instruction for programming Richard Heathfield <rjh@cpax.org.uk> - 2015-04-13 10:32 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 02:53 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 11:04 +0100
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-13 14:10 +0200
Re: primitive instruction for programming Emiliano Gomes Padilha <egpadilha@gmail.com> - 2015-04-20 14:27 -0700
Re: primitive instruction for programming Emiliano Gomes Padilha <egpadilha@gmail.com> - 2015-04-20 15:12 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-21 00:17 +0100
Re: primitive instruction for programming Emiliano Gomes Padilha <egpadilha@gmail.com> - 2015-04-22 11:07 -0700
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-21 09:04 +0200
Re: primitive instruction for programming Robert Wessel <robertwessel2@yahoo.com> - 2015-04-21 03:02 -0500
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-21 01:34 -0700
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-21 11:34 +0200
Re: primitive instruction for programming Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-21 11:48 +0100
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-21 13:10 +0200
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-21 10:53 +0100
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 20:09 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 12:48 -0700
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-14 09:40 +0200
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-14 11:24 +0100
Re: primitive instruction for programming Robert Wessel <robertwessel2@yahoo.com> - 2015-04-14 05:39 -0500
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-14 13:29 +0200
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 10:59 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 03:28 -0700
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 03:33 -0700
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 03:59 -0700
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 04:23 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 11:36 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 04:26 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 12:41 +0100
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 06:26 -0700
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-13 15:33 +0200
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 06:44 -0700
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-13 16:30 +0200
Re: primitive instruction for programming Ian Collins <ian-news@hotmail.com> - 2015-04-14 07:52 +1200
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-14 09:47 +0200
Re: primitive instruction for programming raltbos@xs4all.nl (Richard Bos) - 2015-04-14 08:10 +0000
Re: primitive instruction for programming David Brown <david.brown@hesbynett.no> - 2015-04-14 10:40 +0200
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-13 17:52 +0000
Re: primitive instruction for programming Robert Wessel <robertwessel2@yahoo.com> - 2015-04-13 18:20 -0500
Re: primitive instruction for programming Robert Wessel <robertwessel2@yahoo.com> - 2015-04-13 18:33 -0500
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-14 19:51 +0000
Re: primitive instruction for programming Tim Rentsch <txr@alumni.caltech.edu> - 2015-04-16 09:04 -0700
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-17 02:25 +0000
Re: primitive instruction for programming Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-17 08:34 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-17 17:49 +0100
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-17 19:06 +0000
Re: primitive instruction for programming Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-17 20:45 -0700
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-18 16:43 +0000
Re: primitive instruction for programming Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-04-18 09:56 -0700
Re: primitive instruction for programming Stephen Sprunk <stephen@sprunk.org> - 2015-04-17 17:52 -0500
Re: primitive instruction for programming Morris Dovey <mrdovey@iedu.com> - 2015-04-17 18:02 -0500
Re: primitive instruction for programming Stephen Sprunk <stephen@sprunk.org> - 2015-04-17 19:26 -0500
Re: primitive instruction for programming Morris Dovey <mrdovey@iedu.com> - 2015-04-17 20:04 -0500
Re: primitive instruction for programming Michael Angelo Ravera <maravera@prodigy.net> - 2015-04-19 14:59 -0700
Re: primitive instruction for programming Richard Heathfield <rjh@cpax.org.uk> - 2015-04-20 00:19 +0100
Re: primitive instruction for programming Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-20 02:06 +0100
Re: primitive instruction for programming Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-20 02:26 +0100
Re: primitive instruction for programming Richard Heathfield <rjh@cpax.org.uk> - 2015-04-20 02:18 +0100
Re: primitive instruction for programming Tim Rentsch <txr@alumni.caltech.edu> - 2015-04-18 18:59 -0700
Re: primitive instruction for programming Steve Thompson <stevet810@gmail.com> - 2015-04-19 16:28 +0000
Re: primitive instruction for programming Richard Damon <Richard@Damon-Family.org> - 2015-04-19 17:16 -0400
Re: primitive instruction for programming Tim Rentsch <txr@alumni.caltech.edu> - 2015-04-22 15:28 -0700
Re: primitive instruction for programming John Bode <jfbode1029@gmail.com> - 2015-04-23 07:20 -0700
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 03:07 -0700
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 09:47 -0700
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 11:09 -0700
Re: primitive instruction for programming Noob <root@127.0.0.1> - 2015-04-13 20:43 +0200
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 12:09 -0700
Re: primitive instruction for programming Xcott Craver <xcottcraver@gmail.com> - 2015-04-14 07:11 -0700
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-14 07:28 -0700
Re: primitive instruction for programming Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-14 15:57 +0100
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-14 08:13 -0700
Re: primitive instruction for programming fir <profesor.fir@gmail.com> - 2015-04-13 14:02 -0700
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 14:28 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 22:51 +0100
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 14:58 -0700
Re: primitive instruction for programming Bartc <bc@freeuk.com> - 2015-04-13 23:25 +0100
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 15:37 -0700
Re: primitive instruction for programming James Kuyper <jameskuyper@verizon.net> - 2015-04-13 19:09 -0400
Re: primitive instruction for programming fmassei@gmail.com - 2015-04-13 16:20 -0700
Re: primitive instruction for programming Robert Wessel <robertwessel2@yahoo.com> - 2015-04-13 18:03 -0500
Re: primitive instruction for programming asetofsymbols@gmail.com - 2015-04-13 20:58 -0700
Re: primitive instruction for programming fir <profesor.fir@gmail.com> - 2015-04-13 15:02 -0700
csiph-web