[Solved] write a function which takes a linked list as a parameter and returns nodes found in even positions in the original list


typedef struct node {
    int data;
    struct node* next;
} node;

node *copyEven(node *mylist){
    node *newHead = NULL, *temptr = NULL;
    int count = 1;

    while(mylist){
        if ( count % 2 == 0){
            node* newNode = malloc(sizeof(node));
            newNode->data = mylist->data;
            newNode->next = NULL;
            if(newHead == NULL){
                temptr = newHead = newNode;
            } else {
                temptr = temptr->next = newNode;
            }
        }
        count++;
        mylist = mylist->next;
    }
    return newHead;
}

2

solved write a function which takes a linked list as a parameter and returns nodes found in even positions in the original list