Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class DumbFibonacci extends ActivationRecord{
- int temp=0;
- public DumbFibonacci(ArrayList<Integer> arr){
- currentLine = 1;
- arglist = arr;
- }
- void methodBody(){
- switch(currentLine){
- case 1: {
- lineOne(arglist.get(0));
- break;
- }
- case 2: {
- lineTwo(arglist.get(0));
- break;
- }
- case 3: {
- lineThree(arglist.get(0));
- break;
- }
- case 4: {
- lineFour(arglist.get(0));
- break;
- }
- case 5: {
- System.out.println("popping DumbFibonacci(" + arglist.get(0) + ") with result = " + result);
- endProcess(); // pop this call from the stack
- break;
- }
- default: {
- break;
- }
- }
- }
- void lineOne(int k){
- System.out.println("pushing DumbFibonacci(" + k + ")");
- if (k <= 1) {
- currentLine = 5; // base case - exit
- result = 1;
- }
- else currentLine++; // or continue to next line
- }
- void lineTwo(int count) {
- ArrayList<Integer> arr = new ArrayList<Integer>(3);
- arr.add(count-2);
- callingStack.push(new DumbFibonacci(arr));
- currentLine++; // on to next line
- }
- void lineThree(int count) {
- this.temp=result;
- ArrayList<Integer> arr = new ArrayList<Integer>(3);
- arr.add(count-1);
- callingStack.push(new DumbFibonacci(arr));
- currentLine++;
- }
- void lineFour(int count) {
- result=this.result + temp;
- currentLine++; // on to next line
- }
- public static void main(String [] args){
- ProcessStack ps = new ProcessStack();
- ArrayList<Integer> arr = new ArrayList<Integer>(3);
- arr.add(4);
- DumbFibonacci ft = new DumbFibonacci(arr);
- ps.workStack(ft);
- }
- }
Add Comment
Please, Sign In to add comment