# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13702 | EE2310_Lec_9_1 |
|
13706 | EE2310_Lec_9_2 |
|
Description
/* --- DO NOT SUBMIT main() !!! --- */
/* --- submit EVERYTHING ELSE except main() --- */
/* --- containing the #include directives and struct definition --- */
#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_list(linked_list_t *ptr_list) {
/*
* Use your code for Lecture 8-2
*/
}
void add_node(linked_list_t *list_ptr, int data) {
/*
* Use your code for Lecture 8-2
*/
}
node_t* find_middle(linked_list_t *list_ptr) {
/*
* Your code here
*/
}
void free_list(linked_list_t *ptr_list) {
/*
* Your code here.
* You should return the memory for each node in the list using a loop.
*/
}
Input
8
1 2 3 4 5 6 7 8
Output
mid = 5
Sample Input Download
Sample Output Download
Partial Judge Code
13702.cPartial Judge Header
13702.hTags
Discuss
Description
/* --- DO NOT SUBMIT main() !!! --- */
/* --- submit EVERYTHING ELSE except main() --- */
/* --- containing the #include directives and struct definition --- */
#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*) {
/*
* You can use Lec 9-1's code here
*/
}
void free_list(linked_list_t*) {
/*
* You can use Lec 9-1's code here
*/
}
void output_list(linked_list_t*) {
/*
* You can use Lec 9-1's code here
*/
}
void add_node(linked_list_t*, int) {
/*
* You can use Lec 9-1's code here
*/
}
void reverse_list(linked_list_t*) {
/*
* 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);
}
reverse_list(&my_list);
output_list(&my_list);
free_list(&my_list);
return 0;
}
Input
8
1 2 3 4 5 6 7 8
Output
8 7 6 5 4 3 2 1