Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > recursion

Reply
Thread Tools

recursion

 
 
Default User
Guest
Posts: n/a
 
      08-16-2007
oliver wrote:


> Thanks for your unhelpful responses - what a waste of your time and
> mine.


This is an easy *plonk*.



Brian
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      08-16-2007
"Default User" <(E-Mail Removed)> writes:

> oliver wrote:
>
>
>> Thanks for your unhelpful responses - what a waste of your time and
>> mine.

>
> This is an easy *plonk*.


Impressive. Do keep us informed on who you plonk and it would also be
beneficial to us all if you reply about 30 times to OT messages in order
to reduce the noise in this NG.

Sheesh....
 
Reply With Quote
 
 
 
 
Mark McIntyre
Guest
Posts: n/a
 
      08-16-2007
On Thu, 16 Aug 2007 10:18:18 -0700, in comp.lang.c , oliver
<(E-Mail Removed)> wrote:

>Thanks for your unhelpful responses - what a waste of your time and
>mine.


Frankly - you started it.

>I posted on a C group because I used this board many years ago when I
>was heavily involved in C programming and found the people helpful and
>knowledgable.


I find the people over in rec.motorcycles helpful and knowledgeable
too, but I'm not going to ask them for recipes for fairy cakes.

>I do take your point on board that a more generic .programming group
>my help and will post there too.


Its your best bet I think.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
Reply With Quote
 
John Bode
Guest
Posts: n/a
 
      08-16-2007
On Aug 16, 11:00 am, oliver <(E-Mail Removed)> wrote:
> I'd like to code something recursively - it's not going to be in C
> (VBA actually) but I hope this is the best place to ask.
> I have a Bill of Materials structured like this:
>
> row description
> 1 main assembly
> 2 .subassembly (of 1)
> 3 ..subassembly (of 2)
> 4 .subassembly (of 1)
> 5 ..subassembly (of 4)
> 6 ...subassembly (of 5)
> 7 .subassembly (of 1)
>
> and I need to turn this into a table that looks like this
> row parent
> 1 -
> 2 1
> 3 2
> 4 1
> 5 4
> 6 5
> 7 1
>
> The (of 1, of 2) in the descritpions don't actually exist in the data,
> the dots preceeding the description tell you that.
>
> Ok so please help - I've been chipping away at this for hours and it's
> so long since I did my degree I've gone a bit dopey and can't see the
> wood from the trees. I "KNOW" the most elegant way to handle this is
> recursively I just can't figure out how today.
>


Why do you KNOW a recursive solution is the most elegant? Because I
just came up with a non-recursive solution that works pretty well and
is reasonably straightforward:

int rownum = 1;
int stack[STACK_SIZE];
char record[RECORD_SIZE];

stack[0] = rownum;

printf("%8s%8s\n", "row", "parent");
printf("%8s%8s\n", "---", "------");
while (fgets(record, sizeof record, data))
{
int parent = 0;
int level = getLevel(record); //getLevel counts leading '.'
if (level > 0)
{
parent = stack[level - 1];
stack[level] = rownum;
}
printf("%%8d%8d\n", rownum, parent);
rownum++;
}

Should be enough to get you started, anyway.

 
Reply With Quote
 
oliver
Guest
Posts: n/a
 
      08-17-2007
On 16 Aug, 22:57, John Bode <(E-Mail Removed)> wrote:
> On Aug 16, 11:00 am, oliver <(E-Mail Removed)> wrote:
>
>
>
>
>
> > I'd like to code something recursively - it's not going to be in C
> > (VBA actually) but I hope this is the best place to ask.
> > I have a Bill of Materials structured like this:

>
> > row description
> > 1 main assembly
> > 2 .subassembly (of 1)
> > 3 ..subassembly (of 2)
> > 4 .subassembly (of 1)
> > 5 ..subassembly (of 4)
> > 6 ...subassembly (of 5)
> > 7 .subassembly (of 1)

>
> > and I need to turn this into a table that looks like this
> > row parent
> > 1 -
> > 2 1
> > 3 2
> > 4 1
> > 5 4
> > 6 5
> > 7 1

>
> > The (of 1, of 2) in the descritpions don't actually exist in the data,
> > the dots preceeding the description tell you that.

>
> > Ok so please help - I've been chipping away at this for hours and it's
> > so long since I did my degree I've gone a bit dopey and can't see the
> > wood from the trees. I "KNOW" the most elegant way to handle this is
> > recursively I just can't figure out how today.

>
> Why do you KNOW a recursive solution is the most elegant? Because I
> just came up with a non-recursive solution that works pretty well and
> is reasonably straightforward:
>
> int rownum = 1;
> int stack[STACK_SIZE];
> char record[RECORD_SIZE];
>
> stack[0] = rownum;
>
> printf("%8s%8s\n", "row", "parent");
> printf("%8s%8s\n", "---", "------");
> while (fgets(record, sizeof record, data))
> {
> int parent = 0;
> int level = getLevel(record); //getLevel counts leading '.'
> if (level > 0)
> {
> parent = stack[level - 1];
> stack[level] = rownum;
> }
> printf("%%8d%8d\n", rownum, parent);
> rownum++;
> }
>
> Should be enough to get you started, anyway.- Hide quoted text -
>
> - Show quoted text -


I did it like this in the end
k = START_ROW
While Cells(k, INDENTURE_COL) = 0
For i = k To lngMaxRow
If Cells(i, INDENTURE_COL) > 0 Then
intThisIndent = Cells(i, INDENTURE_COL)
If intThisIndent > j Then
j = j + 1
aryParent(j) = Cells(i - 1, INDEX_COL)
Else
j = intThisIndent
End If
l = l + 1
Sheets("Hierarchy").Cells(l, 1) = Cells(i, INDEX_COL)
Sheets("Hierarchy").Cells(l, 2) = aryParent(j)
End If
Next i
k = k + 1
Wend

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
DNS recursion question while studying for 70-293 Kevin Porter MCSE 1 03-18-2006 05:56 AM
DNS recursion question while studying for 70-293 Kevin Porter Microsoft Certification 0 03-16-2006 11:10 PM
recursion with perl B McInnes Perl 4 11-04-2003 06:08 AM
Output buffering problems during recursion Tim Mohler Perl 1 09-16-2003 12:35 AM



Advertisments