Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace NodeExamples
- {
- class Program
- {
- static void Main(string[] args)
- {
- Node<int> day = new Node<int>(17);
- Node<int> month = new Node<int>(8);
- day.SetNext(month);
- month.SetNext(new Node<int>(2005));
- Node<String> name = new Node<string>("Mohamad", new Node<string>("Mazin", new Node<string>("Ayoub")));
- Console.WriteLine(Print(day));
- Console.WriteLine(isExist(day, 12));
- Console.WriteLine(isExist(day, 2005));
- }
- public static bool isOrderd(Node<int> chain)
- {
- Node<int> pos = chain;
- while (pos.HasNext())
- {
- if (pos.GetValue() > pos.GetNext().GetValue())
- return false;
- pos = pos.GetNext();
- }
- return true;
- }
- public static bool isExist(Node<int> chain, int x )
- {
- Node<int> pos = chain;
- while (pos != null) {
- if (pos.GetValue() == x)
- return true;
- pos = pos.GetNext();
- }
- return false;
- }
- public static string Print(Node<int> X)
- {
- string A = "[";
- Node<int> P1 = X;
- while (P1 != null)
- {
- A = A + P1.GetValue().ToString();
- if (P1.HasNext())
- {
- A = A + ",";
- }
- else
- {
- A = A + "]";
- }
- P1 = P1.GetNext();
- }
- return A;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement