public static int noOfElementsGreaterThan <T>(Repository.Stack <T> stack, T elem) where T : Model.Comparable <T> { int result = 0; Repository.Stack <T> temp = stack.copy(); while (!temp.isEmpty()) { Model.Comparable <T> comparableElem = temp.pop(); if (comparableElem.isGreaterThan(elem)) { result++; } } return(result); }
public static void moveElements <W, T>(Repository.Stack <W> source, Repository.Stack <T> destination) where W : T { Repository.Stack <T> temp = new Repository.Stack <T>(); try { while (!source.isEmpty()) { temp.push(source.pop()); } while (!temp.isEmpty()) { destination.push(temp.pop()); } } catch (MyException e) { System.Console.WriteLine(e.getMessage()); } }
public static String elementsFromStack <T>(Repository.Stack <T> stack) { Repository.Stack <T> copy = stack.copy(); String result = "\n"; while (!copy.isEmpty()) { try { T element = copy.pop(); result += element.ToString(); result += "\n"; } catch (MyException ex) { return(ex.getMessage()); } } return(result); }