fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node{
  4. int data;
  5. struct node *next;
  6. };
  7. void main(){
  8. struct node *head=NULL;
  9. head=malloc(sizeof(struct node));
  10. head->data=34;
  11. head->next=NULL;
  12. struct node *first=NULL;
  13. first=malloc(sizeof(struct node));
  14. first->data=56;
  15. first->next=NULL;
  16. head->next=first;
  17. struct node *second=NULL;
  18. second=malloc(sizeof(struct node));
  19. second->data=88;
  20. second->next=NULL;
  21. first->next=second;
  22. second->next=head;
  23. struct node *ptr=head;
  24. int pos,cnt=0;
  25. struct node *temp=NULL;
  26. temp=malloc(sizeof(struct node));
  27. temp->data=78;
  28. printf("enter pos to print:");
  29. scanf("%d\n",pos);
  30. while(cnt!=pos)
  31. { cnt++;
  32. ptr=ptr->next;
  33. }
  34. ptr->next=temp;
  35. temp->next=ptr->next->next;
  36. }
Success #stdin #stdout 0.02s 25000KB
stdin
Standard input is empty
stdout
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node *next;
};
void main(){
  struct node *head=NULL;
  head=malloc(sizeof(struct node));
  head->data=34;
  head->next=NULL;
  struct node *first=NULL;
  first=malloc(sizeof(struct node));
  first->data=56;
  first->next=NULL;
  head->next=first;
  struct node *second=NULL;
  second=malloc(sizeof(struct node));
  second->data=88;
  second->next=NULL;
  first->next=second;
  second->next=head;
  struct node *ptr=head;
  int pos,cnt=0;
  struct node *temp=NULL;
  temp=malloc(sizeof(struct node));
  temp->data=78;
  printf("enter pos to print:");
  scanf("%d\n",pos);
  while(cnt!=pos)
  { cnt++;
  ptr=ptr->next;
  }
  ptr->next=temp;
  temp->next=ptr->next->next;
}