2220 - I2P(I)2020_Huang_lab12 Scoreboard

Time

2020/12/21 08:00:00 2020/12/21 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

13043 - Dynamic Stacks using Dynamic Arrays   

Description

Define dynamic stacks as follows.

struct stack {
   int *stack_buffer;
   int top;   
   int max_size;
};

Implement the following four functions as shown in 13043.c.

  1. void stack_init(struct stack *s, int size);
    • Use dynamic memory allocation to allocate appropriate memory according to size.
  2. void stack_destroy(struct stack *s);
    • Free the stack’s memory
  3. void dyn_push(int elem, struct stack *s);
    • Push elem to the stack. If it is full, double its size and push elem.
  4. int dyn_pop(struct stack *s);
    • Pop an element from the stack as return value.
    • If top < max_size/4, shrink the stack’s size by half (as max_size/2).
    • If the stack is empty before the pop operation, use printf("Stack is empty!\n"); and return the value -100000.
  5. int show_stack(struct stack *s);
    • If stack is empty, print "Empty", Else; print "Stack contains "
    • Loop through the stack, printing all of the elements in the buffer.
    • Finally, print "top=%d, max_size=%d\n"

UPDATE:

If you have presentation error issues please consider formatting your printf statements as follows:

  • " top=%d, max_size=%d\n"

 

The following must be included when submitting:

#include <stdio.h>
#include <stdlib.h>

struct stack {
   int *stack_buffer;
   int top;  
   int max_size;
};

/* Your Code Here. */

void function1(...)
void function2(...)

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

13043.c

Partial Judge Header

13043.h

Tags




Discuss




13044 - Dynamic Stacks using Linked Lists   

Description

Define a stack node as

struct stacknode {
   int data;
   struct stacknode ∗next;
};


Implement the following four functions as shown in 13044.c:

  1. void push(struct stacknode **ptr2head, int elem);
    • Since the stack top has to be modified during pushing, we send a pointer to pointer to struct stacknode.
  2. int pop(struct stacknode **ptr2head);
    • We send a pointer to pointer to struct stacknode for the same reason.
    • After popping, you should return the memory of the popped element.
    • If the stack is empty and nothing can be popped, use  printf("stack is empty!\n");
  3. void show(struct stacknode *head);
    • Show all elements in the stack beginning with the top element.
    • If the stack is empty, use printf("empty stack\n");

The following must be included when submitting:

#include <stdio.h>
#include <stdlib.h>

struct stacknode {
   int data;
   struct stacknode *next;
};

/* Your Code Here. */

void function1(...)

void function2(...)

Input

Output

Sample Input  Download

Sample Output  Download

Partial Judge Code

13044.c

Partial Judge Header

13044.h

Tags




Discuss




13061 - Fibonacci Sequence   

Description

The Fibonacci sequence is a sequence where the next term is the sum of the previous two terms. The first two terms of the Fibonacci sequence are 0 followed by 1.

 

For example,

 

We have provided the partial judge code (13061.c) below for you.

All you need to do is complete the int fib(int n) function and submit it to NTHU Online Judge System.

int fib(int n){

             ...

             ...

}

 

Attention: Using recursion to solve this problem.

 

Input

Given an integer n, where n >= 0

 

Output

Print out the F0 to Fn

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13061.c

Partial Judge Header

13061.h

Tags




Discuss




13062 - Reverse a String using Recursion   

Description

Please write a recursive program to reverse a given string.

 

We have provided the partial judge code (13062.c) below for you.

All you need to do is complete the void reverse(char *str, int k) function and submit it to NTHU Online Judge System.

void reverse(char *str, int k){

             ...

             ...

}

 

Attention: Using recursion to solve this problem.

 

Input

Given a string.

 

Output

Print the reversed string.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13062.c

Partial Judge Header

13062.h

Tags




Discuss