• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Recursion, with using Lists to store data

 
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am struggling with this problem for long time and i haven't found any simple solutions.

As you can see i have made simple list to store numbers from 0 to 4, but the problem it gets the stackOverFlowError.
The result should be list.get(0) = 0 ... and list.get(3) = 4

 
Saloon Keeper
Posts: 14490
325
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".
 
mandlar suurla
Ranch Hand
Posts: 67
PHP Debian Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Hey there! Can you explain in your own words what the difference is between:

++counter;
and
counter++?

If you don't know the difference, look up what the difference is between prefix increment and postfix increment.

Take note that the correct words are "recursion" and "recursive", not "recrusion" and "recrusive".


prefix increment, the statement value is increased first before use, but postfix increment takes value and then increases.

example
counter = 0;

if (++counter) -- the counter is increased first and then the boolean check if (1)

if (counter++) -- counter is increased after use in statement if (0) and then make +1

Am I right ? But the problem still lies in recursion.
 
Stephan van Hulst
Saloon Keeper
Posts: 14490
325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[edit]

Actually no, there are no checks. The prefix operator first increases the variable, and then returns the value. The postfix operator increases the variable, but returns the value it was before the increment.
How could this affect your recursion?
 
reply
    Bookmark Topic Watch Topic
  • New Topic