Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication20
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- // תרגיל 1
- public static bool checkit(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = copy(s);
- bool check = false;
- for(int i=0;!temp.IsEmpty();i++)
- {
- temp.Pop();
- for(int j=0;temp.IsEmpty();j++)
- {
- if (s.Top() == temp.Top())
- {
- check = false;
- s.Pop();
- }
- else
- check = true;
- }
- }
- return check;
- }
- public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
- Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
- while (!s.IsEmpty())
- {
- temp.Push(s.Pop());
- }
- while (!temp.IsEmpty())
- {
- s.Push(temp.Pop());
- temp.Push(temp.Pop());
- }
- return temp1;
- }
- }
- }
- // תרגיל 2
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication22
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- public static int checkSize(Unit4.CollectionsLib.Stack<int> t)
- {
- int count = 0;
- while (!t.IsEmpty())
- {
- count++;
- t.Pop();
- }
- return count;
- }
- public static int CheckMe(Unit4.CollectionsLib.Stack<int> s)
- {
- int countit = (checkSize(s) / 2);
- Unit4.CollectionsLib.Stack<int> temp =Program.copy(s);
- if (checkSize(s) % 2 != 0)
- {
- for (int i = 0; i < countit+1; i++)
- {
- temp.Pop();
- }
- }
- return temp.Top();
- int sum=0;
- int avg;
- if (checkSize(s) % 2 == 0)
- {
- while (!temp.IsEmpty())
- {
- temp.Pop();
- for (int i = 0; i < countit; i++)
- {
- sum += temp.Pop();
- avg = sum / countit;
- }
- }
- }
- return avg;
- }
- public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
- Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
- while (!s.IsEmpty())
- {
- temp.Push(s.Pop());
- }
- while (!temp.IsEmpty())
- {
- s.Push(temp.Pop());
- temp.Push(temp.Pop());
- }
- return temp1;
- }
- }
- }
- // תרגיל 3
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication21
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- public static int Sum(Unit4.CollectionsLib.Stack<int> s)
- {
- int sum=0;
- Unit4.CollectionsLib.Stack<int> temp = Program.copy(s);
- while (!temp.IsEmpty())
- {
- sum += temp.Top();
- temp.Pop();
- }
- return sum;
- }
- public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
- Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
- while (!s.IsEmpty())
- {
- temp.Push(s.Pop());
- }
- while (!temp.IsEmpty())
- {
- s.Push(temp.Pop());
- temp.Push(temp.Pop());
- }
- return temp1;
- }
- }
- }
- // תרגיל 6
- using System;
- using Unit4.CollectionsLib;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication79
- {
- class Program
- {
- static void Main(string[] args)
- {
- }
- public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
- Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
- while (!s.IsEmpty())
- {
- temp.Push(s.Pop());
- }
- while (!temp.IsEmpty())
- {
- s.Push(temp.Pop());
- temp.Push(temp.Pop());
- }
- return temp1;
- }
- public static Unit4.CollectionsLib.Stack<int> NewS(Unit4.CollectionsLib.Stack<int> s)
- {
- Unit4.CollectionsLib.Stack<int> temp = Program.copy(s);
- Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
- while (!temp.IsEmpty())
- {
- if (s.Top() < temp.Top())
- {
- temp1.Push(temp.Top());
- temp.Pop();
- }
- }
- return temp1;
- }
- }
- }
Add Comment
Please, Sign In to add comment