Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int?[] myArr = new int?[4];
- string command = string.Empty;
- int cnt = 0;
- while (!command.Equals("end"))
- {
- command = Console.ReadLine();
- if (command.Contains("push"))
- {
- int number = int.Parse(command.Split().Last());
- myArr[cnt] = number;
- cnt++;
- if (cnt == myArr.Length)
- {
- Array.Resize<int?>(ref myArr, myArr.Length * 2);
- }
- }
- else if (command.Contains("removeAt"))
- {
- int index = int.Parse(command.Split().Last());
- myArr[index] = null;
- for (int i = index; i < myArr.Length - 1; i++)
- {
- myArr[i] = myArr[i + 1];
- }
- cnt--;
- }
- else if (command.Equals("pop"))
- {
- myArr[cnt - 1] = null;
- cnt--;
- }
- else if (command.Equals("clear"))
- {
- for (int i = 0; i < myArr.Length; i++)
- {
- myArr[i] = null;
- Array.Resize<int?>(ref myArr, 4);
- }
- cnt = 0;
- }
- }
- if (myArr[0] == null)
- {
- Console.WriteLine("empty array");
- }
- else
- {
- Console.WriteLine(string.Join(" ", myArr));
- }
Advertisement
Add Comment
Please, Sign In to add comment