Loading...

Във форума е въведено ограничение, което позволява на потребителите единствено да разглеждат публикуваните въпроси.

Itsa_Georgieva avatar Itsa_Georgieva 1 Точки

C# Advanced May 2021 - Iterators and Comparators - Exercise - 03. Stack

3.   Stack

Create your custom stack. You are aware of the Stack's structure. There is a collection to store the elements and two functions (not from the functional programming) - to push an element and to pop it. Keep in mind that the first element, which is popped is the last in the collection. The Push method adds an element at the top of the collection and the Pop method returns the top element and removes it. Push and Pop will be the only commands and they will come in the following format:

"Push {element1}, {element2}, … {elementN}

 Pop

… "

Write your custom implementation of Stack<T> and implement IEnumerable<T> interface. Your implementation of the GetEnumerator() method should follow the rules of the Abstract Data Type – Stack (return the elements in reverse order of adding them to the stack).

Input

  • The input will come from the console as lines of commands.
  • and pop will be the only possible commands, followed by integers for the push command and no another input for the pop command.

Output

  • When you receive END, the input is over. the stack twice and print all elements each on new line.

Constraints

  • The elements in the push command will be valid integers
  • The commands will always be valid always be Push, Pop or END).
  • If Pop command could not be executed as expected e.g. no elements in the stack), print on the console: "No elements".

Examples

Input

Output

Push 1, 2, 3, 4

Pop

Pop

END

2

1

2

1

Push 1, 2, 3, 4

Pop

Push 1

END

1

3

2

1

1

3

2

1

Push 1, 2, 3, 4

Pop

Pop

Pop

Pop

Pop

END

No elements

 

https://pastebin.com/mauZUWmJ - класа Stack

https://pastebin.com/5hZzXrY7 - StartUp

Преписвам буквално кода от лекцията, нулевите тестове минават, както и 1-ви тест, но 3-ти тест ми дава runtime error и 50/100 в judge.

 

 

 

0
C# Advanced 18/06/2021 14:36:28
icowwww avatar icowwww 2673 Точки

Здравей,

В Pop хвърляш throw new ArgumentException("No elements");, а в main метода се опитваш да хванеш catch (AggregateException ae).

Трябва да са еднакви:

Примерна промяна в main метода- ред 37: https://pastebin.com/fxXCUypy

0
Itsa_Georgieva avatar Itsa_Georgieva 1 Точки

Ама разбира се...Благодаря! Сега остава да попрочета за Exception-ите, че нищо не ми говорят blush

0
Можем ли да използваме бисквитки?
Ние използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Можете да се съгласите с всички или част от тях.
Назад
Функционални
Използваме бисквитки и подобни технологии, за да предоставим нашите услуги. Използваме „сесийни“ бисквитки, за да Ви идентифицираме временно. Те се пазят само по време на активната употреба на услугите ни. След излизане от приложението, затваряне на браузъра или мобилното устройство, данните се трият. Използваме бисквитки, за да предоставим опцията „Запомни Ме“, която Ви позволява да използвате нашите услуги без да предоставяте потребителско име и парола. Допълнително е възможно да използваме бисквитки за да съхраняваме различни малки настройки, като избор на езика, позиции на менюта и персонализирано съдържание. Използваме бисквитки и за измерване на маркетинговите ни усилия.
Рекламни
Използваме бисквитки, за да измерваме маркетинг ефективността ни, броене на посещения, както и за проследяването дали дадено електронно писмо е било отворено.