Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.84 KB | None | 0 0
  1. using System;
  2. using Unit4.CollectionsLib;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication20
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.         }
  13. // תרגיל 1
  14.         public static bool checkit(Unit4.CollectionsLib.Stack<int> s)
  15.         {
  16.             Unit4.CollectionsLib.Stack<int> temp = copy(s);
  17.             bool check = false;
  18.                 for(int i=0;!temp.IsEmpty();i++)
  19.                 {
  20.                    temp.Pop();
  21.                     for(int j=0;temp.IsEmpty();j++)
  22.                     {
  23.                         if (s.Top() == temp.Top())
  24.                         {
  25.                             check = false;
  26.                             s.Pop();
  27.                            
  28.                            
  29.                         }
  30.                         else
  31.                             check = true;
  32.                            
  33.                        
  34.                     }
  35.                 }
  36.                 return check;
  37.                        
  38.             }
  39.         public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
  40.         {
  41.             Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
  42.             Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
  43.             while (!s.IsEmpty())
  44.             {
  45.                 temp.Push(s.Pop());
  46.             }
  47.             while (!temp.IsEmpty())
  48.             {
  49.                 s.Push(temp.Pop());
  50.                 temp.Push(temp.Pop());
  51.             }
  52.             return temp1;
  53.         }
  54.        
  55.         }
  56. }
  57. // תרגיל 2
  58.  
  59. using System;
  60. using Unit4.CollectionsLib;
  61. using System.Linq;
  62. using System.Text;
  63.  
  64. namespace ConsoleApplication22
  65. {
  66.     class Program
  67.     {
  68.         static void Main(string[] args)
  69.         {
  70.  
  71.         }
  72.  
  73.         public static int checkSize(Unit4.CollectionsLib.Stack<int> t)
  74.         {
  75.             int count = 0;
  76.             while (!t.IsEmpty())
  77.             {
  78.                 count++;
  79.                 t.Pop();
  80.  
  81.             }
  82.             return count;
  83.         }
  84.  
  85.         public static int CheckMe(Unit4.CollectionsLib.Stack<int> s)
  86.         {
  87.             int countit = (checkSize(s) / 2);
  88.             Unit4.CollectionsLib.Stack<int> temp =Program.copy(s);
  89.             if (checkSize(s) % 2 != 0)
  90.             {
  91.                 for (int i = 0; i < countit+1; i++)
  92.                 {
  93.                     temp.Pop();
  94.                 }
  95.  
  96.                
  97.             }
  98.             return temp.Top();
  99.  
  100.             int sum=0;
  101.             int avg;
  102.  
  103.             if (checkSize(s) % 2 == 0)
  104.             {
  105.                 while (!temp.IsEmpty())
  106.                 {
  107.                     temp.Pop();
  108.                     for (int i = 0; i < countit; i++)
  109.                     {
  110.                         sum += temp.Pop();
  111.                         avg = sum / countit;
  112.                     }
  113.                    
  114.                 }
  115.             }
  116.             return avg;
  117.  
  118.  
  119.         }
  120.  
  121.         public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
  122.         {
  123.             Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
  124.             Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
  125.             while (!s.IsEmpty())
  126.             {
  127.                 temp.Push(s.Pop());
  128.             }
  129.             while (!temp.IsEmpty())
  130.             {
  131.                 s.Push(temp.Pop());
  132.                 temp.Push(temp.Pop());
  133.             }
  134.             return temp1;
  135.         }
  136.  
  137.     }
  138. }
  139.  
  140. // תרגיל 3
  141.  
  142. using System;
  143. using Unit4.CollectionsLib;
  144. using System.Linq;
  145. using System.Text;
  146.  
  147. namespace ConsoleApplication21
  148. {
  149.     class Program
  150.     {
  151.         static void Main(string[] args)
  152.         {
  153.         }
  154.  
  155.         public static int Sum(Unit4.CollectionsLib.Stack<int> s)
  156.         {
  157.             int sum=0;
  158.             Unit4.CollectionsLib.Stack<int> temp = Program.copy(s);
  159.             while (!temp.IsEmpty())
  160.             {
  161.                 sum += temp.Top();
  162.                 temp.Pop();
  163.             }
  164.             return sum;
  165.         }
  166.  
  167.          public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
  168.       {
  169.             Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
  170.            Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
  171.            while (!s.IsEmpty())
  172.             {
  173.                 temp.Push(s.Pop());
  174.             }
  175.            while (!temp.IsEmpty())
  176.             {
  177.                 s.Push(temp.Pop());
  178.               temp.Push(temp.Pop());
  179.             }
  180.           return temp1;
  181.         }
  182.     }
  183. }
  184.  
  185. // תרגיל 6
  186. using System;
  187. using Unit4.CollectionsLib;
  188. using System.Linq;
  189. using System.Text;
  190.  
  191. namespace ConsoleApplication79
  192. {
  193.     class Program
  194.     {
  195.         static void Main(string[] args)
  196.         {
  197.         }
  198.         public static Unit4.CollectionsLib.Stack<int> copy(Unit4.CollectionsLib.Stack<int> s)
  199.         {
  200.             Unit4.CollectionsLib.Stack<int> temp = new Stack<int>();
  201.             Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
  202.             while (!s.IsEmpty())
  203.             {
  204.                 temp.Push(s.Pop());
  205.             }
  206.             while (!temp.IsEmpty())
  207.             {
  208.                 s.Push(temp.Pop());
  209.                 temp.Push(temp.Pop());
  210.             }
  211.             return temp1;
  212.         }
  213.  
  214.         public static Unit4.CollectionsLib.Stack<int> NewS(Unit4.CollectionsLib.Stack<int> s)
  215.         {
  216.             Unit4.CollectionsLib.Stack<int> temp = Program.copy(s);
  217.             Unit4.CollectionsLib.Stack<int> temp1 = new Stack<int>();
  218.             while (!temp.IsEmpty())
  219.             {
  220.                 if (s.Top() < temp.Top())
  221.                 {
  222.  
  223.                     temp1.Push(temp.Top());
  224.                     temp.Pop();
  225.                 }
  226.             }
  227.             return temp1;
  228.         }
  229.  
  230.     }
  231. }
Add Comment
Please, Sign In to add comment