Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // list<T> ////////////
- int[] arr1 = {1,2,3,4,5,6,7};
- int[] arr2 = {2,3,4,5,6,7,8};
- int[] kur = new int[0];
- kur = Union(arr1, arr2);
- for (int i = 0; i < 8; i++)
- {
- Console.WriteLine(kur[i] + " ");
- }
- }
- public static int[] Union(int[] firstarr, int[] secondarr)
- {
- List<int> union = new List<int>();
- union.AddRange(firstarr);
- foreach (var item in secondarr)
- {
- if (! union.Contains(item))
- {
- union.Add(item);
- }
- }
- return union.ToArray();
- }
- ///////// 2 primer vzima samo suvpadashtite 4isla ot 2ta masiva ///////////////////
- static void Main(string[] args)
- {
- int[] arr1 = {2,3,4,5,6,9};
- int[] arr2 = {7,8,2,5};
- int[] kur = new int[0];
- kur = Inter(arr1, arr2);
- for (int i = 0; i < 22; i++)
- {
- Console.WriteLine(kur[i] + " ");
- }
- }
- public static int[] Inter(int[] firstarr, int[] secondarr)
- {
- List<int> union = new List<int>();
- foreach (var item in firstarr)
- {
- if (Array.IndexOf(secondarr, item) != -1)
- {
- union.Add(item);
- }
- }
- return union.ToArray();
- }
- ////////////// stack primer sus stek ////////////////////////////////////////////
- Stack<string> stek = new Stack<string>();
- stek.Push("1. ivan");
- stek.Push("2. divan");
- stek.Push("3. many");
- stek.Push("4. floyd");
- stek.Push("5. kondio");
- Console.WriteLine("top = {0}", stek.Peek());
- while (stek.Count > 0)
- {
- string name = stek.Pop();
- Console.WriteLine(name);
- }
- //////////////////// stack primer brackets /////////////////////////////////
- string expr = "1 + (2 - (2+3) * 4 / (3+1)) + 5";
- Stack<int> stek = new Stack<int>();
- for (int i = 0; i < expr.Length; i++)
- {
- char ch = expr[i];
- if (ch == '(')
- {
- stek.Push(i);
- }
- else if (ch == ')')
- {
- int startIndex = stek.Pop();
- int length = i - startIndex + 1;
- string contents = expr.Substring(startIndex, length);
- Console.WriteLine(contents);
- }
- }
- ////////////////////////////////// stack primer s start i end index ///////////////////////////////////////
- int[] array = { 2, 3, -6, -1, 2, -1, 6, 4, -8, 8 };// ako si sloja 9 she mi zeme do 9
- Stack<int> stek = new Stack<int>();
- int currentSum = array[0];
- int startIndex = 0;
- int endIndex = 0;
- int maxSum = array[0];
- int count = 0;
- for (int i = 1; i < array.Length; i++)
- {
- if (currentSum < 0)
- {
- currentSum = array[i];
- stek.Push(i);
- }
- else
- {
- currentSum += array[i];
- count++;
- }
- if (i != 1)
- {
- if (currentSum > maxSum)
- {
- maxSum = currentSum;
- startIndex = stek.Pop() + 1;
- endIndex = (i+1) - count + startIndex;
- }
- }
- }
- Console.WriteLine("The best sum is: {0} ", maxSum);
- Console.WriteLine("The best sequence is:");
- for (int i = startIndex; i <= endIndex; i++)
- {
- Console.Write(i != endIndex ? array[i] + ", " : array[i] + "\n");
- }
- Console.WriteLine();
- /////////////////////// queue opashka primer ///////////////////////////////////////////////
- Queue<string> opshka = new Queue<string>();
- opshka.Enqueue("1 kondio");
- opshka.Enqueue("2 ondio");
- opshka.Enqueue("3 ndio");
- opshka.Enqueue("4 dio");
- opshka.Enqueue("5 io");
- while (opshka.Count > 0)
- {
- string mas = opshka.Dequeue();
- Console.WriteLine(mas);
- }
- ///////////////////// opshka primer s 4isla ///////////////////
- int n = 3;
- int p = 16;
- Queue<int> opshka = new Queue<int>();
- opshka.Enqueue(n);
- int index = 0;
- while (opshka.Count > 0)
- {
- int current = opshka.Dequeue();
- index++;
- if (current == p)
- {
- Console.WriteLine("Index = {0}", index);
- }
- opshka.Enqueue(current + 1);
- opshka.Enqueue(2 * current);
- }
- ////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement