Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace classwork
- {
- class MyStack
- {
- private int[] array;
- private int index;
- public MyStack(int size = 64)
- {
- array = new int[size];
- index = 0;
- }
- public bool isOverflow()
- {
- return array.Length == index;
- }
- public bool isEmpty()
- {
- return index == 0;
- }
- public int Size
- {
- get
- {
- return index;
- }
- }
- public int MaxSize
- {
- get
- {
- return array.Length;
- }
- }
- public void MaxCount(out int count)
- {
- count = 0;
- int max = array[0];
- for (int i = 0; i < index; i++)
- {
- if (max < array[i])
- {
- max = array[i];
- count = 1;
- }
- else if (max == array[i])
- count++;
- }
- }
- public void MinCount(out int count)
- {
- count = 0;
- int min = array[0];
- for (int i = 0; i < index; i++)
- {
- if (min > array[i])
- {
- min = array[i];
- count = 1;
- }
- else if (min == array[i])
- count++;
- }
- }
- public void PushBack(params int[] values)
- {
- for (int i = 0; i < values.Length && index != array.Length; i++)
- array[index++] = values[i];
- }
- public int? PopBack()
- {
- if (index != 0)
- return array[--index];
- return null;
- }
- public int[] PopBack(int count) // извлечение элементов по номерам противоречит идеологии стека
- {
- int trueSize = 0;
- int[] result = new int[count];
- for (int i = 0; i < count && index != 0; i++)
- {
- result[i] = array[--index];
- trueSize++;
- }
- Array.Resize(ref result, trueSize);
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement