Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(head==NULL){
- return NULL;
- }
- if(head->next != NULL && head->next->next==NULL){
- struct node* first = malloc(sizeof(struct node));
- memcpy(head,first, sizeof(struct node));
- first->next=NULL;
- return first;
- }
- struct node* current = head->next;
- int index = 1;
- struct node* tempPointer = (struct node*) malloc(sizeof(struct node));
- struct node* tempax = tempPointer;
- if(tempPointer==NULL){
- free(tempPointer);
- return NULL;
- }
- memcpy(tempPointer,head, sizeof(struct node));
- while(current != NULL){
- if(index%2 ==0){
- tempPointer->next=malloc(sizeof(struct node));
- memcpy(tempPointer->next, current, sizeof(struct node));
- tempPointer=tempPointer->next;
- }
- current = current->next;
- index ++;
- }
- return tempax;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement