# Thread: fixedPoint for Stacks

1. Member
Join Date
Jun 2013
Posts
62
Rep Power
0

## fixedPoint for Stacks

Hi guys

Have some questions on this problem.

Here is my answer for part 1 :

Java 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()
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){
}
}
}```
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?

2. ## Re: fixedPoint for Stacks

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

3. Member
Join Date
Jun 2013
Posts
62
Rep Power
0

## Re: fixedPoint for Stacks

part 2 which is the fixedpoint.

4. ## Re: fixedPoint for Stacks

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

5. Member
Join Date
Jun 2013
Posts
62
Rep Power
0

## 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.

6. Member
Join Date
Jul 2013
Posts
1
Rep Power
0

## Re: fixedPoint for Stacks

can anyone explain part 2? i'm kinda lost what it is looking for...
Last edited by kanasuke; 07-17-2013 at 10:56 AM.

7. ## Re: fixedPoint for Stacks

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

8. ## 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.

9. Member
Join Date
Jun 2013
Posts
62
Rep Power
0

## 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.

10. ## Re: fixedPoint for Stacks

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

11. ## Re: fixedPoint for Stacks

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

12. ## 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
Edited to add: should I read that web site? or book?
regards
dhilip
Last edited by noobplus; 07-17-2013 at 09:42 AM.

13. Member
Join Date
Jun 2013
Posts
62
Rep Power
0

## Re: fixedPoint for Stacks

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
Edited to add: should I read that web site? or book?
regards
dhilip
and why are you commenting on my thread?

14. ## Re: fixedPoint for Stacks

i was anti-bumping go get your question right from Short, Self Contained, Correct Example

15. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
2,673
Rep Power
3

## Re: fixedPoint for Stacks

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

16. ## Re: fixedPoint for Stacks

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

17. Member
Join Date
Jun 2013
Posts
62
Rep Power
0