3 Replies - 9466 Views - Last Post: 04 December 2007 - 06:54 AM Rate Topic: -----

#1 sunsan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 07

linked list / recursion

Posted 03 December 2007 - 01:31 PM

Hello,
Oops! I might have posted this in the wrong place before. :unsure:
I'm new to the site. I'm not a novice programmer, but this java problem has me stumped.

I don't have any code to post yet, I've only developed the GUI interface.

The homework assignment is as follows:
We are not to use the LinkedList data collection supplied with Java. We are to create our own nodes and the methods.
Each method must be written recursively.

The 'user' enters a name, adress, etc on the form field. The code is susposed to add the fields to a linked list.
I created a node with the proper fields and I have method stubs.

My question is what to do with the fields once the user has entered the data? Do I store them somehow, and then recursively add them to the linked list? If I add the fields as the user enters them, then it really won't be a recursive method.
I'm perplexed as to where to start with this assignment.

Thanks for any help.
Sunsan

Is This A Good Question/Topic? 0
  • +

Replies To: linked list / recursion

#2 skaoth   User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: linked list / recursion

Posted 03 December 2007 - 06:30 PM

Quote

if I add the fields as the user enters them, then it really won't be a recursive method


I don't think that this statement is necesarly true.
All that recursion means is a function/method that calls itself.
Now that I think about it, it doesn't really matter if you store the users
information first and then place them into your linked list
or if you add the information right away to your linked list.
In the end you will still need to call your linked list's add method N times.

Lets assume you have a AddEntry(class Entry, class &node) method to your linked list implementation.
The requirement is that this method be recursive.

So it might look something like this
Note: Please forgive my java. It is very, very rusty.
// This is just pseudo code. I also assume this is a singly linked list.

public void AddEntry(class Entry, class node)
{
	if(node != null && node.next == null)
   {
		 // Add node to the end of the list
   }
   else
	   AddEntry(Entry, node.next);
	
}



Is this even remotly close to what what you need?
Was This Post Helpful? 0
  • +
  • -

#3 sunsan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 07

Re: linked list / recursion

Posted 04 December 2007 - 06:49 AM

View Postskaoth, on 3 Dec, 2007 - 06:30 PM, said:

Quote

if I add the fields as the user enters them, then it really won't be a recursive method


I don't think that this statement is necesarly true.
All that recursion means is a function/method that calls itself.
Now that I think about it, it doesn't really matter if you store the users
information first and then place them into your linked list
or if you add the information right away to your linked list.
In the end you will still need to call your linked list's add method N times.

Lets assume you have a AddEntry(class Entry, class &node) method to your linked list implementation.
The requirement is that this method be recursive.

So it might look something like this
Note: Please forgive my java. It is very, very rusty.
// This is just pseudo code. I also assume this is a singly linked list.

public void AddEntry(class Entry, class node)
{
	if(node != null && node.next == null)
   {
		 // Add node to the end of the list
   }
   else
	   AddEntry(Entry, node.next);
	
}



Is this even remotly close to what what you need?

Was This Post Helpful? 0
  • +
  • -

#4 sunsan   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-December 07

Re: linked list / recursion

Posted 04 December 2007 - 06:54 AM

Thank you so much.

That was exactly what I needed to get my head on straight.
I understand what is expected now.
I was thinking that the fields would need to be added recursively, but that's not necesarily true. As long as the method is written recursively, that's the point of the exercise.

Thanks again.
Sunsan
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1