David Goins

Greenhorn
+ Follow
since Oct 07, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Goins

Well from the code the "add" only adds whatever is placed into the list and does not need anything returned from that. So i figure the return would be void... But that's just with me guessing and looking at what the code "should" be doing.

I set them all to void and it compiled... it seems to be working now..

David
15 years ago
OK Ritchie i finally solved that prob. but i still have 3 errors that i dont know how to correct. It seems one is asking for a void while the other is returning a Boolean?


And heres the code the errors refer too:




David
[ October 27, 2008: Message edited by: David Goins ]
15 years ago
Ok, re-worked:

However i am still getting an error:

I'm not getting why it has an error on the "theList = f.getNext();" when both are defined as integers... What am i doing wrong there?

David
15 years ago
Ok worked on it some more and i talked with my teacher... heres what i got now:

So now im on the:


write the countValue method which accomplishes the followings:

1. it has 2 parameters:
* the unlist
* an int v
2. declare an int counter a.
3. declare a for loop that will run 20 times in which you will do the following:
* get the first element from the unlist, say f1.
* make sure you compare f1 to v.
* if they are equal increment the counter a.
4. return a.
5. done


However, this is the errors i get

I need some help getting the RefUnsortedList value from "f"...

David
15 years ago
Thanks for the reply again Ritchie:

However this is the errors i get when i compile it:

And here is the updated code:

David
15 years ago
Ok how close (or far) am i with this:



David
15 years ago
Ritchie:

This may help you and me more.. its some "hints" for getting this flowing:


* Declare an unsortedlinkedlist unlist.
* use a for loop in which you will do the following 20 times:
1. create a random number between 0 and 4
2. insert the number into the unlist
* print the elements in unlist.
* call the countValue method 5 times where each time you will send 2 parameters:
1. the unlist
2. the value of an int that is 0,1,2,3,4
* write the countValue method which accomplishes the followings:
1. it has 2 parameters:
o the unlist
o an int i
2. declare an int counter a.
3. make a list element out of the element i, say f2.
4. declare a for loop that will run 20 times in which you will do the following:
o get the first element from the unlist, say f1.
o make sure you compare f1 to f2.
o if they are equal increment the counter a.
5. return a.
6. done


I dont see a "LLNode<E>" in any class'es this program uses.... Is that the section i need to add to RefList.java? I really dont see anything in the chapter that has anything close to explaining what "LLNode<E>" does...

David
15 years ago
Then Ritchie would i use:

David
15 years ago
This doesnt seem to work either...

David
15 years ago
How about this?


David
15 years ago
Hey Ritchie: Yes that's the class on the page that we have to use with this assignment. In the chapter it has nothing about the "add" statement in order to get stuff into the list so i'm up a creak without a paddle per say. Is there a site that has the "add" method for the RefList? Seems redundant not having that in the class in the first place....

And I'm really not getting the "int countValue(RefList f, int item);"... Nowhere in that does it have the "size()" command found in the RefList that could be used to get how many items are in the list without having to do all that???

David
15 years ago
Hey all i am trying to figure out how to get this RefList working for me...


Implement a method countValue() that counts the number of times an item occurs in a linked list.

int countValue(RefList f, int item);

Generate 20 random numbers in the range of 0 to 4, and insert each number at the front of a linked list. Output the list by using a method which you would call writeLinkedList which you would add to the RefList.java (in page 414-421) program. In a loop, call the method countValue() , and display the number of occurrences of each value from 0 to 4 in the list.



So far this is what i have:

But there's an error for the "refl1.add(intRandomNum);" since the RefList class does not have a "add" property. How am i supposed to add to a list that has no command to add?

Here is the RefList code:

Thanks!
David
15 years ago
Ok i finally got it myself..

Thank you to those who helped

David
15 years ago
Ok thanks for clearing that up Campbell Ritchie.

It seems to work but i am having problems with the output now...

I'm trying to get a list of all the evens with "evens = even.top();" and then keep looping until its empty so i can have the output look like this "10 8 36 100 26 88 4 2 16" But right now it has an error saying:

If i just do this:

Then it outputs the numbers i posted above down the line like so:


David
15 years ago
Ok thanks Campbell Ritchie but i still have the error on the pop() statment.

Here is the updated code:

The top() works just fine and displays "1" but once i add the pop it has the error.

David
15 years ago