Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stack {
- private Node head;
- public Node next;
- public Stack() {
- head = new Node();
- head.data = 0;
- }
- public Stack( int d ) {
- head = new Node();
- head.data = d;
- }
- public int pop() {
- int temp;
- temp = head.data;
- head = head.next;
- return temp;
- }
- public void push( int d ) {
- Node tmp = new Node();
- tmp.data = d;
- tmp.next = head;
- head = tmp;
- }
- public int peek() {
- return head.data;
- }
- //Private Class
- private class Node{
- int data;
- Node next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement