14124 - EE2310_Lab9_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 8-2
 */
}

 

void add_node(linked_list_t *list_ptr, int data) {
/*
 * Use your code in Lecture 8-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 */);

    printf("\n");
    return 0;
}

 

Input

5
1 33 53 5 9

Output

1_33_53_5_9_
9_5_53_33_1_

Sample Input  Download

Sample Output  Download

Tags




Discuss