Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. if(head==NULL){
  2. return NULL;
  3. }
  4. if(head->next != NULL && head->next->next==NULL){
  5. struct node* first = malloc(sizeof(struct node));
  6. memcpy(head,first, sizeof(struct node));
  7. first->next=NULL;
  8. return first;
  9. }
  10. struct node* current = head->next;
  11. int index = 1;
  12.  
  13. struct node* tempPointer = (struct node*) malloc(sizeof(struct node));
  14. struct node* tempax = tempPointer;
  15. if(tempPointer==NULL){
  16. free(tempPointer);
  17. return NULL;
  18. }
  19. memcpy(tempPointer,head, sizeof(struct node));
  20.  
  21. while(current != NULL){
  22. if(index%2 ==0){
  23. tempPointer->next=malloc(sizeof(struct node));
  24. memcpy(tempPointer->next, current, sizeof(struct node));
  25. tempPointer=tempPointer->next;
  26. }
  27. current = current->next;
  28. index ++;
  29. }
  30. return tempax;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement