Skip to content

Instantly share code, notes, and snippets.

@karan-ta
Created November 8, 2016 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karan-ta/408100c624a12ef18db9a4833c4de6cf to your computer and use it in GitHub Desktop.
Save karan-ta/408100c624a12ef18db9a4833c4de6cf to your computer and use it in GitHub Desktop.
public class Lesson2{
private static void push(int[] stack,int elem,int top){
stack[top] = elem++;
//top = 0
top++;
//top = 1 top is just a local variable -
//changes made to it are not passed to main function
}
//1,0,0,0,0,0,0,0,0,0,0,0
public static void main(String[] args){
int[] stack = new int[10]; // our stack is forever limited to the size 10
int top = 0;
Lesson2.push(stack,1,top);
Lesson2.push(stack,2,top)// top = 0 !!!!
System.out.println(Arrays.toString(stack));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment