Advertisement
haquaa

Untitled

Jan 4th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Queuee
  7. {
  8.     class Queue
  9.     {
  10.         Node front = null;
  11.         Node rear = null;
  12.  
  13.         public void push(int val)
  14.         {
  15.             Node tmp = new Node(val);
  16.             if (front == null && rear == null)
  17.             {
  18.                 front = tmp;
  19.                 rear = tmp;
  20.                 return;
  21.             }
  22.  
  23.             rear.next = tmp;
  24.             rear = tmp;
  25.         }
  26.  
  27.         public int top()
  28.         {
  29.             if (front == null)
  30.             {
  31.                 return 0;
  32.             }
  33.             return front.info;
  34.         }
  35.  
  36.         public void pop()
  37.         {
  38.             if (front == null)
  39.             {
  40.                 return;
  41.             }
  42.             front = front.next;
  43.         }
  44.  
  45.         public bool empty()
  46.         {
  47.             return (front == null);
  48.         }
  49.  
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement