13715 - EE2310_Lec_10_2   

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! 

Sample Input  Download

Sample Output  Download

Tags




Discuss