/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
//Exam
public static bool exist(BinNode<int> bt, int x)
{
if (bt == null)
return false;
if(bt.GetValue() == x)
return true;
return exist(bt.GetLeft(), x) || exist(bt.GetRight(), x);
}
static Node<int> Check(BinNode<int> bt1, BinNode<int> bt2, Node<int> list)
{
if (bt1 == null)
return null;
if (!exist(bt2,bt1.GetValue()))
{
list.SetNext(new Node<int>(bt1.GetValue(), list.GetNext()));
}
list = Check(bt1.GetLeft(), bt2, list);
list = Check(bt1.GetRight(), bt2, list);
return list;
}
static void Main() {
Console.WriteLine("Hello World");
//الفئات المطلوبة لمباني المعلومات
}
}
public class Node<T>
{
//------------------------------------------------
private T Value;
private Node<T> Next;
//------------------------------------------------
public Node(T Value)
{
this.Value = Value;
this.Next = null;
}
//------------------------------------------------
public Node(T Value, Node<T> Next)
{
this.Value = Value;
this.Next = Next;
}
//------------------------------------------------
public T GetValue()
{
return this.Value;
}
//------------------------------------------------
public void SetValue(T Value)
{
this.Value = Value;
}
//------------------------------------------------
public Node<T> GetNext()
{
return this.Next;
}
//------------------------------------------------
public void SetNext(Node<T> Next)
{
this.Next = Next;
}
//------------------------------------------------
public bool HasNext()
{
return (this.Next != null);
}
//------------------------------------------------
public override string ToString()
{
return base.ToString();
}
}
public class Queue <T>
{
private Node <T> First, Last;
public Queue()
{
this.First =null;
this.Last =null;
}
public bool IsEmpty()
{
return this.First ==null;
}
public T Head ()
{
return this.First.GetValue();
}
public void Insert(T x)
{
Node<T> temp = new Node<T>(x);
if(First == null){
First = temp;
Last = temp;
}
else
{
Last.SetNext(temp);
Last = Last.GetNext();
}
}
public T Remove()
{
T x= this.First.GetValue();
this.First =this.First.GetNext();
return x;
}
public override string ToString()
{
string str="[";
Node<T> Pos = this.First;
while ( Pos != null)
{
if (Pos.HasNext())
str += Pos.GetValue() +",";
else
str += Pos.GetValue();
Pos =Pos.GetNext();
}
return str + "]";
}
}
public class Stack<T>
{
private Node<T> Head;
public Stack()
{
this.Head = null;
}
public bool IsEmpty()
{
return this.Head == null;
}
public T Top()
{
return this.Head.GetValue();
}
public void Push(T x)
{
Node<T> Temp = new Node<T>(x);
if (Head == null)
Head = Temp;
else
{
Temp.SetNext(Head);
Head = Temp;
}
}
public T Pop()
{
T x = this.Head.GetValue();
this.Head = this.Head.GetNext();
return x;
}
public override string ToString()
{
string str = "[";
Node<T> Pos = this.Head;
while (Pos != null)
{
if (Pos.HasNext())
str += Pos.GetValue() + ",";
else
str += Pos.GetValue();
Pos = Pos.GetNext();
}
return str + "]";
}
}
public class BinNode<T>
{
//------------------------------------------------
private T Value;
private BinNode<T> Left, Right;
//------------------------------------------------
public BinNode(T Value)
{
this.Value = Value;
this.Left = null;
this.Right = null;
}
//------------------------------------------------
public BinNode(BinNode<T> Left, T Value, BinNode<T> Right)
{
this.Value = Value;
this.Left = Left;
this.Right = Right;
}
//------------------------------------------------
public T GetValue()
{
return this.Value;
}
//------------------------------------------------
public void SetValue(T Value)
{
this.Value = Value;
}
//------------------------------------------------
public BinNode<T> GetLeft()
{
return this.Left;
}
//------------------------------------------------
public BinNode<T> GetRight()
{
return this.Right;
}
//------------------------------------------------
public void SetLeft(BinNode<T> Left)
{
this.Left = Left;
}
//------------------------------------------------
public void SetRight(BinNode<T> Right)
{
this.Right = Right;
}
//------------------------------------------------
public bool HasLeft()
{
return (this.Left != null);
}
//------------------------------------------------
public bool HasRight()
{
return (this.Right != null);
}
//------------------------------------------------
public override string ToString()
{
return base.ToString();
}
}
//سلسة مترابطة من اتجاهين
public class BiDirNode<T>
{
private T Value;
private BiDirNode<T> Next;
private BiDirNode<T> Prev;
public BiDirNode()
{
}
public BiDirNode( T Value)
{
this.Value = Value;
this.Next = null;
this.Prev = null;
}
public BiDirNode( BiDirNode<T>Prev ,T Value, BiDirNode<T> Next)
{
this.Value = Value;
this.Next = Next;
this.Prev = Prev;
}
public T GetValue()
{
return this.Value;
}
public void SetValue(T Value)
{
this.Value = Value;
}
public BiDirNode<T> GetNext()
{
return this.Next;
}
public void SetPrev(BiDirNode<T> Prev)
{
this.Next = Prev;
}
public BiDirNode<T> GetPrev()
{
return this.Prev;
}
public void SetNext(BiDirNode<T> Next)
{
this.Next = Next;
}
public bool HasNext()
{
return this.Next != null;
}
public bool HasPrev()
{
return this.Prev != null;
}
}