# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13714 | EE2310_Lec_10_1 |
|
13715 | EE2310_Lec_10_2 |
|
Description
Redo the palindrome problem (Lec 4-2 ) using recursion. You cannot use the old version, otherwise not only will you get no credits for this lecture, we will take PENALTY points.
重做 Lec 4-2 palindrome 那一題,請用“遞迴函式”的方法,否則不但不算分還會被倒扣分數!
Input
abcba
Output
a palindrome
Sample Input Download
Sample Output Download
Tags
Discuss
Description
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *next;
};
typedef struct node node_t;
typedef struct linked_list {
node_t *head;
node_t *tail;
} linked_list_t;
void initialize(linked_list_t *list_ptr) {
list_ptr->head = NULL;
list_ptr->tail = NULL;
}
void output(/* define your own arguments */) {
/*
* Re-write this using recursion
* DO NOT reuse your code in Lecture 9-1/9-2
*/
}
void add_node(linked_list_t *list_ptr, int data) {
/*
* Use your code in Lecture 9-1/9-2
*/
}
void free_list(linked_list_t *ptr_list) {
/*
* Use your code in Lecture 9-1/9-2
*/
}
void reverse_output(/* define your own arguments */) {
/*
* Your code here
*/
}
int main(){
linked_list_t my_list;
initialize(&my_list);
node_t *middle_ptr;
int data, input_size;
/* when you add a node, you add it at the tail */
scanf("%d\n", &input_size);
for(int i=0; i < input_size; ++i) {
scanf("%d", &data);
add_node(&my_list, data);
}
output(/* add your own arguments */);
reverse_output(/* add your own arguments */);
free_list(&my_list);
return 0;
}
Input
7
1 2 3 4 5 6 7
Output
1 2 3 4 5 6 7 <- there's a whitespace at the end!
7 6 5 4 3 2 1 <- there's a whitespace but no '\n' at the end!