# fixedPoint for Stacks

• 07-15-2013, 02:10 PM
Malv
fixedPoint for Stacks
Hi guys

Have some questions on this problem.

Here is my answer for part 1 :

Code:

```public void stackArrange(ArrayList list1, ArrayList list2){         Stack s = new ArrayStackImpl();         while(!list1.isEmpty()){             if(s.empty() == true){                 s.push(list1.get(list1.size() -1));                 list1.remove(list1.size() - 1);             }else if(list1.get(list1.size() -1).toString().compareTo(s.top().toString()) > 0){ // if e > s.top()                 list2.add(s.pop());                 if(s.empty() == true || s.top().toString().compareTo(list1.get(list1.size() -1).toString()) >= 0){//s.empty == true || s.top >= e                     s.push(list1.get(list1.size() -1));                     list1.remove(list1.size() - 1);                 }             }else if(list1.get(list1.size() -1).toString().compareTo(s.top().toString()) <= 0){ // e <= s.top()                 s.push(list1.get(list1.size() -1));                 list1.remove(list1.size() - 1);             }         }         if(list1.isEmpty()){             while(s.empty() == false){                 list2.add(s.pop());             }         }     }```
Once you have answered part 1 above add a second method to your Arranger class with the signature:

public void fixedPoint(ArrayList list1,
ArrayList list2)

fixedPoint repeatedly feeds list1 through stackArrange until the output of stackArrange is the same as its input. This process of feeding the result of a method to itself until it stops changing its input is called reaching a fixed-point. Once the input stops changing you should return this result in list2.

In implementing fixedPoint you will need to record the previous input to stackArrange so you can compare it with the output. You can test fixedPoint using ArrangerDriver2.java in the starting files. The result you should get is not specified here (you can probably guess what the result will be) but, given the way that stackArrange works you can know it will be a permuation of list1.

Can anyone explain what does fixedPoint do?
• 07-15-2013, 02:35 PM
JosAH
Re: fixedPoint for Stacks
Quote:

Originally Posted by Malv
Hi guys

Have some questions on this problem.

Here is my answer for part 1 :

What problem? What part 1?

Jos
• 07-15-2013, 02:41 PM
Malv
Re: fixedPoint for Stacks
part 2 which is the fixedpoint.
• 07-15-2013, 02:57 PM
JosAH
Re: fixedPoint for Stacks
Quote:

Originally Posted by Malv
part 2 which is the fixedpoint.

What part 2? Care to show us mortals the problem description? Or do we have to guess ...

Jos
• 07-15-2013, 03:00 PM
Malv
Re: fixedPoint for Stacks
Once you have answered part 1 above add a second method to your Arranger class with the signature:

public void fixedPoint(ArrayList list1,
ArrayList list2)

fixedPoint repeatedly feeds list1 through stackArrange until the output of stackArrange is the same as its input. This process of feeding the result of a method to itself until it stops changing its input is called reaching a fixed-point. Once the input stops changing you should return this result in list2.

In implementing fixedPoint you will need to record the previous input to stackArrange so you can compare it with the output. You can test fixedPoint using ArrangerDriver2.java in the starting files. The result you should get is not specified here (you can probably guess what the result will be) but, given the way that stackArrange works you can know it will be a permuation of list1.
• 07-17-2013, 08:01 AM
kanasuke
Re: fixedPoint for Stacks
can anyone explain part 2? i'm kinda lost what it is looking for...
• 07-17-2013, 08:24 AM
JosAH
Re: fixedPoint for Stacks
Quote:

Originally Posted by kanasuke
bump...

can anyone explain part 2? i'm kinda lost what it is looking for...

And who are you? Bumping some else's thread? The OP didn't bother to tell us the requirements (we had to guess) and he finally gave us part of it while the other part(s) are also essential to the problem; that's why everybody can only ignore this thread. A fixed point x w.r.t. a relation R is a point such that R(x) == x; that's all I can say about it. Better PM the OP so you can work on this problem together.

kind regards,

Jos
• 07-17-2013, 08:27 AM
noobplus
Re: fixedPoint for Stacks
Hi, I forgot all java basics, since I had some short term memory problems, Now what should I do? I've interview day after tomorrow on Core Java . I've downloaded Cay S HorstMann's e-book.
• 07-17-2013, 08:32 AM
Malv
Re: fixedPoint for Stacks
I allow bumping from anyone and anyone can comment on these issues. Mods just dont see people of the same problem trying to solve the same problem in a thread.
• 07-17-2013, 08:34 AM
noobplus
Re: fixedPoint for Stacks
Quote:

Originally Posted by Malv
I allow bumping from anyone and anyone can comment on these issues.

but both of them will have incomplete questions as a result

regards
dhilip
• 07-17-2013, 08:35 AM
JosAH
Re: fixedPoint for Stacks
Quote:

Originally Posted by noobplus
Hi, I forgot all java basics, since I had some short term memory problems, Now what should I do? I've interview day after tomorrow on Core Java . I've downloaded Cay S HorstMann's e-book.

Cancel the appointment and protect yourself from a disgraceful failure.

Jos
• 07-17-2013, 08:39 AM
noobplus
Re: fixedPoint for Stacks
But I know all class rules, I can make it.. I'm studying fields atm.. I remember file handling , and still I doubt this article would help me...
interview core java 129 questions
regards
dhilip
• 07-17-2013, 08:44 AM
Malv
Re: fixedPoint for Stacks
Quote:

Originally Posted by noobplus
But I know all class rules, I can make it.. I'm studying fields atm.. I remember file handling , and still I doubt this article would help me...
interview core java 129 questions
regards
dhilip

and why are you commenting on my thread?
• 07-17-2013, 09:03 AM
noobplus
Re: fixedPoint for Stacks
i was anti-bumping go get your question right from Short, Self Contained, Correct Example
• 07-17-2013, 09:17 AM
gimbal2
Re: fixedPoint for Stacks
Am I alone when I say that I am completely and utterly confused about what this thread is all about!?
• 07-17-2013, 09:31 AM
JosAH
Re: fixedPoint for Stacks
Quote:

Originally Posted by gimbal2
Am I alone when I say that I am completely and utterly confused about what this thread is all about!?

Nope, it's hopeless; I'm out of this thread.

kind regards,

Jos
• 07-17-2013, 04:17 PM
Malv
Re: fixedPoint for Stacks