Page 1 of 1 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 17:38 Post subject: Java problems |
|
 |
Someone implement this crap in Java or C for the love of God! an d its 30% of my grade ..i will paypal you 1$
A recursive procedure to find the max of a nonvoid list.
Assume we have built-in functions called
• Length, which returns the number of elements
in a list
• Max, which returns the larger of two values
• Listhead, which returns the first element in a list
Max requires one comparison.
Code: | procedure maxlist (list)
/* strip off head of list and pass the remainder */
if Length(list) = 1 then
return Listhead(list)
else
return Max( Listhead(list),
maxlist(remainder of
list)) |
The recurrence equation for the number of comparisons required for a list of length n,
f(n), is
• f(1) = 0
• f(n) = 1 + f(n-1)
when I look at this

|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 17:44 Post subject: |
|
 |
You already have the recursion implemented? Just implement in Java or C, what is the problem?
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 17:49 Post subject: |
|
 |
iNatan wrote: | You already have the recursion implemented? Just implement in Java or C, what is the problem? |
I don't know!
I don't know to write a program to show output of that :\ and I had java for 1.5yrs 

Last edited by Przepraszam on Sat, 17th Dec 2011 17:50; edited 1 time in total
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 17:49 Post subject: |
|
 |
Crude C implementation.
Code: | T maxList(List* l)
{
if(l->next == NULL)
return l->head;
return MAX(l->head, maxList(l->next));
} |
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 17:52 Post subject: |
|
 |
Please, speak to me more in langauge that I don't understand
All, I see are chinese symbols!
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 17:53 Post subject: |
|
 |
Perhaps you would point out what you don't understand so we can help better? 
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 17:55 Post subject: |
|
 |
I don't know. Instructiions are not clear.
I need to use either Java or C to run that problem for three different values of N
|
|
Back to top |
|
 |
garus
VIP Member
Posts: 34200
|
Posted: Sat, 17th Dec 2011 17:55 Post subject: |
|
 |
snip
Last edited by garus on Tue, 27th Aug 2024 21:29; edited 1 time in total
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 17:58 Post subject: |
|
 |
garus wrote: | You ask for code, you get it and then you complain you don't understand? How do you expect people to help you? |
I don't program on daily basis. All I ever wrote is Hello World program in my entire life. heh.
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 17:59 Post subject: |
|
 |
So how do you get from hello world program to recursion? Do you even understand the principle of recursion? Do you understand the algorithm that you yourself posted in your original post? If not, then you should first understand these fundamentals before you ask for code.
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 18:09 Post subject: |
|
 |
iNatan wrote: | So how do you get from hello world program to recursion? Do you even understand the principle of recursion? Do you understand the algorithm that you yourself posted in your original post? If not, then you should first understand these fundamentals before you ask for code. |
I wouldn't post this, if I knew how to do all of this and understand this. It's not even for Java class but for discrete mathematics.
Well recursion is like dividing a problem into smaller parts until you run out of things to do?
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 18:10 Post subject: |
|
 |
OK, so taking "dividing into smaller parts" into account, what are the small parts in our problem?
|
|
Back to top |
|
 |
|
Posted: Sat, 17th Dec 2011 18:24 Post subject: |
|
 |
Actually recursion is when a function calls on itself (from inside the function obviously).
Usually the one example people use when trying to explain recursion if the fibonacci numbers example.
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 18:26 Post subject: |
|
 |
madmax17 wrote: | Actually recursion is when a function calls on itself (from inside the function obviously). |
That's a technical implementation. What besthijacker said is correct.
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 18:26 Post subject: |
|
 |
Ohh boy! This makes my head spin.
If we enter value for N, it does some creepy things, it compares the number and returns something depends if its equal to 1 or not? ><
|
|
Back to top |
|
 |
Frant
King's Bounty
Posts: 24433
Location: Your Mom
|
Posted: Sat, 17th Dec 2011 19:42 Post subject: |
|
 |
Besthijacker, how did you manage to NOT learn anything during 1.5 years of Java? What you need is a proper course in OO-programming using anything from VB.NET, C#.NET, Java etc. to C/C++/COBOL/PASCAL or whatever..
string x = "Besthijacker fails";
foreach ((x) in myArray)
{
Console.WriteLine(x));
}
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
"Thank you to God for making me an Atheist" - Ricky Gervais
|
|
Back to top |
|
 |
|
Posted: Sat, 17th Dec 2011 19:58 Post subject: |
|
 |
iNatan wrote: | madmax17 wrote: | Actually recursion is when a function calls on itself (from inside the function obviously). |
That's a technical implementation. What besthijacker said is correct. | Oh yeah, he's a math guy so I guess it's from a mathematical perspective and not programers.
|
|
Back to top |
|
 |
LeoNatan
Banned
Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
|
Posted: Sat, 17th Dec 2011 20:02 Post subject: |
|
 |
No, actually his explanation is correct from programmer's standpoint also.
There is complex recursion which may involve a circular dependency between several functions. That's a different technical implementation, but also recursion.
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Sat, 17th Dec 2011 20:03 Post subject: |
|
 |
Frant wrote: | Besthijacker, how did you manage to NOT learn anything during 1.5 years of Java? What you need is a proper course in OO-programming using anything from VB.NET, C#.NET, Java etc. to C/C++/COBOL/PASCAL or whatever..
string x = "Besthijacker fails";
foreach ((x) in myArray)
{
Console.WriteLine(x));
} |
Heh. I became on good terms with instructors. Fixed his laptop couple of times. So it was automatic A without doing anything.
All he did was copied those newbie programs from the book and try to explain it to us, how they work, Did I also mention, not even once we had to write program on our own.
Problem is from Discrete Mathematics course, I guess lady tried to incorporate programming along with it. Frankly, different instructions teach differently. I have a lot of studying for circuits analysis and theory, it's just too much to learn how to program in-between.
EDIT: So what I should do next? I'm so lost ><
I will just print her instead of
"Hello World"
"This class sucks"
|
|
Back to top |
|
 |
Przepraszam
VIP Member
Posts: 14398
Location: Poland. New York.
|
Posted: Tue, 20th Dec 2011 18:15 Post subject: |
|
 |
I managed to write the code, and it run but i don't think that my logic is correct
ohh well, At least I tried and got some kind of output
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |