static void PredicateTest() { M_Stack <int> ints = new M_Stack <int>(1, 2, 3, 5); M_Stack <int> odds = ints.FindAll(x => x % 2 == 1); odds.Print(); }
public M_Stack(M_Stack <T> other) { Stack_capacity = other.Stack_capacity; Stack_size = other.Stack_size; values = new T[Stack_capacity]; for (int i = 0; i < Stack_size; i++) { values[i] = other.values[i]; } }
static void OperatorTest() { M_Stack <int> a = new M_Stack <int>(12, 45); M_Stack <int> b = new M_Stack <int>(44, 78, 99); M_Stack <int> c = a + b; Console.WriteLine(c); c.Push(7); Console.WriteLine(c); Console.WriteLine(c.Size()); }
static void PredicateTest2() { M_Stack <string> strings = new M_Stack <string>("miras", "didar"); string x = strings.Find(s => s == "x"); List <string> strs = new List <string>() { "nuras", "adel" }; string st = strs.Find(z => z == "x"); Console.WriteLine(st); }
static void Test() { List <int> numbers = new List <int>(); for (int i = 0; i < 100; i += 10) { numbers.Add(i); } M_Stack <int> stack = new M_Stack <int>(numbers); Console.WriteLine(stack[3]); Console.WriteLine(stack); }
public M_Stack <T> FindAll(Predicate <T> predicate) { M_Stack <T> new_stack = new M_Stack <T>(); foreach (T x in values) { if (predicate(x)) { new_stack.Push(x); } } return(new_stack); }
static void Test_String() { List <string> m = new List <string>() { "miras", "didar", "adel", "someone" }; M_Stack <string> m_Stack = new M_Stack <string>(m); Console.WriteLine(m_Stack); foreach (string s in m) { Console.WriteLine(s + ". Now foreach loop works!"); } }
public object Clone() { Console.WriteLine("Cloned"); M_Stack <T> new_stack = new M_Stack <T>(); new_stack.Stack_capacity = this.Stack_capacity; new_stack.values = new T[Stack_capacity]; new_stack.Stack_size = this.Stack_size; for (int i = 0; i < Stack_size; i++) { new_stack.values[i] = this.values[i]; } return(new_stack); }
static public M_Stack <T> operator +(M_Stack <T> a, M_Stack <T> b) { M_Stack <T> result = new M_Stack <T>(a.Stack_capacity + b.Stack_capacity); foreach (T x in a) { result.SimpInsert(x); } foreach (T x in b) { result.SimpInsert(x); } return(result); }