Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Queue
- {
- class Queue
- {
- Node front = null;
- Node rear = null;
- public void push(int val)
- {
- Node tmp = new Node(val);
- if (front == null)
- front = tmp;
- else
- rear.next = tmp;
- rear = tmp;
- }
- public void pop()
- {
- if(front == null)
- {
- Console.WriteLine("Queue is empty");
- }
- front = front.next;
- }
- public int top()
- {
- if (front == null)
- {
- Console.WriteLine("Queue is empty");
- }
- return front.info;
- }
- public bool empty()
- {
- return (front == null);
- }
- }
- }
- ___________________________________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Stack
- {
- class Stack
- {
- Node start = null;
- public void push(int val)
- {
- Node tmp = new Node(val);
- if (start != null)
- {
- tmp.next = start;
- }
- start = tmp;
- }
- public void pop()
- {
- if (start == null)
- {
- return;
- }
- start = start.next;
- }
- public int top()
- {
- if (start == null)
- {
- return 0;
- }
- return start.info;
- }
- public bool empty()
- {
- return (start == null);
- }
- }
- }
- __________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace QueueArray
- {
- class Queue
- {
- int front = -1;
- int rear = -1;
- int[] arr = new int[2000];
- public void push(int val)
- {
- if (rear == arr.Length-1)
- {
- Console.WriteLine("overflow");
- return;
- }
- if (front == -1)
- {
- front++;
- }
- arr[++rear] = val;
- }
- public void pop()
- {
- if (front == -1 || front > rear)
- {
- Console.WriteLine("underflow");
- }
- front++;
- }
- public int top()
- {
- return arr[front];
- }
- public bool empty()
- {
- return (front > rear || (front == -1 && rear == -1));
- }
- }
- }
- _________________________________________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace StackArray
- {
- class Stack
- {
- public int[] arr = new int[5];
- public int top = -1;
- public void push(int val)
- {
- if (top == arr.Length-1)
- {
- Console.WriteLine("overflow");
- return;
- }
- arr[++top] = val;
- }
- public void pop()
- {
- if (top == -1)
- {
- Console.WriteLine("empty");
- return;
- }
- top--;
- }
- public int Top()
- {
- if (top == -1)
- {
- return 0;
- }
- return arr[top];
- }
- public bool isempty()
- {
- return (top == -1);
- }
- }
- }
- _________________________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Tree
- {
- class Tree
- {
- public Node root = null;
- public void insert(int val)
- {
- if (root == null)
- {
- root = new Node(val);
- return;
- }
- root.insertNode(val);
- }
- public void PreOrder(Node x)
- {
- if (x == null) return;
- PreOrder(x.left);
- PreOrder(x.right);
- Console.WriteLine(x.info);
- }
- public void print()
- {
- PreOrder(root);
- }
- /*public int size = 0;
- public void helper(Node x)
- {
- if (x == null) return;
- size++;
- helper(x.left);
- helper(x.right);
- }
- public int count(Node Root)
- {
- helper(Root);
- return size;
- }*/
- }
- class Node
- {
- public int info;
- public Node left;
- public Node right;
- public Node(int val)
- {
- info = val;
- left = right = null;
- }
- public void insertNode(int val)
- {
- if (val >= info)
- {
- if (right == null)
- {
- right = new Node(val);
- return;
- }
- right.insertNode(val);
- }
- else
- {
- if (left == null)
- {
- left = new Node(val);
- return;
- }
- left.insertNode(val);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement