Iterative and recursive method

  1. Write iterative and recursive method that to sum of all positive integers 1 and n.
  2. If given program is executed, what will be output?
    Create Stack
    Queue queue = new LinkedList;
    Create LinkedList ll;
    int[] array = { 16, 22, 399, 214, 351 };

for (i = 0; i < array.length; i++) {
int x = array[i];
if (i % 2 == 0)
addLast(x) in ll;
else
push(x) on stack;
}
while (“stack is not empty” || “linked list is not empty”) {
if (stack is not empty)
queue.enqueue(stack.pop());
if (“linked list is not empty”)
queue.enqueue(ll.removeLast());
if “queue is not empty”)
print("I am " + queue.getFront();}