Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int sumOf(Node<int> l, int k)
- {
- Node<int> s = l;
- int sum = 0;
- while (k > 0)
- {
- sum = sum + s.GetInfo();
- s = s.GetNext();
- k--;
- }
- return sum;
- }
- static bool haveNext(Node<int> l,int k){
- bool booli = true;
- Node<int> s = l;
- while (k > 0)
- {
- l = l.GetNext();
- if (l == null)
- {
- booli = false;
- }
- k--;
- }
- return booli;
- }
- static int lenList(Node<int> l)
- {
- Node<int> temp = l;
- int count = 0;
- while (temp != null)
- {
- count++;
- temp = temp.GetNext();
- }
- return count;
- }
- static bool isCyclic(Node<int> l)
- {
- int m = lenList(l);
- Node<int> p = l;
- bool booli = false;
- while (m > 0)
- {
- if (p.GetInfo() == 1)
- {
- booli = true;
- }
- p = pos(l, p.GetInfo());
- Console.WriteLine(p);
- m--;
- }
- return booli;
- }
- static void nodeToString(Node<int> l)
- {
- Node<int> temp = l;
- while (temp != null)
- {
- Console.Write(temp.GetInfo() + "->");
- temp = temp.GetNext();
- }
- }
- static Node<int> pos(Node<int> l, int p)
- {
- Node<int> temp = l;
- int i = 0;
- Node<int> s = l;
- while (temp != null)
- {
- i++;
- if (p == i)
- {
- s = temp;
- }
- temp = temp.GetNext();
- }
- return s;
- }
- static int queueLength(Queue<int> q)
- {
- Queue<int> temp = cloneQueue(q);
- int i = 0;
- while (!temp.IsEmpty())
- {
- i++;
- temp.Remove();
- }
- return i;
- }
- static bool maagal(Queue<int> q, Queue<int> q1)
- {
- Queue<int> temp = cloneQueue(q);
- int num = queueLength(temp);
- bool booli = false;
- while (num > 0)
- {
- temp.Insert(temp.Remove());
- if (isEqual(temp, q1))
- {
- booli = true;
- }
- num--;
- }
- return booli;
- }
- static bool isEqual(Queue<int> q, Queue<int> q1)
- {
- Queue<int> temp = cloneQueue(q);
- Queue<int> temp1 = cloneQueue(q1);
- if (queueLength(temp) != queueLength(temp1))
- {
- return false;
- }
- int i = queueLength(temp);
- bool booli = true;
- while (!temp.IsEmpty())
- {
- if(!temp.Head().ToString().Equals(temp1.Head().ToString())){
- booli = false;
- }
- temp.Remove();
- temp1.Remove();
- }
- return booli;
- }
- static Queue<int> cloneQueue(Queue<int> q)
- {
- Queue<int> temp1 = new Queue<int>();
- Queue<int> temp2 = new Queue<int>();
- while (!q.IsEmpty())
- {
- temp1.Insert(q.Head());
- temp2.Insert(q.Remove());
- }
- while (!temp2.IsEmpty()) // החזרת התור למצבו המקורי
- {
- q.Insert(temp2.Remove());
- }
- return temp1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement