fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3. #include <cstdio>
  4.  
  5. struct node
  6. {
  7. int i;
  8. node * nxt;
  9. }*head,*a;
  10. int main()
  11. {
  12. int n;
  13. head=new node;
  14. head->i=10;
  15. a=head;
  16. for(int j=0;j<9;j++)
  17. {
  18. node *ptr=new node;
  19. // cout<<"\n enter value :";
  20. cin>>ptr->i;
  21. a->nxt=ptr;
  22. a=ptr;
  23. }
  24. a->nxt=NULL;
  25. a=head;
  26. cout<<"\n before....";
  27. for(int j=0;j<9;j++)
  28. {
  29. cout<<a->i<<"->";
  30. a=a->nxt;
  31. }
  32. cout<<"\n after...";
  33. node *s,*t,*u;
  34. a=head;
  35. head=(a->nxt)->nxt;
  36. while(a!=NULL)
  37. {
  38. u=a->nxt;
  39. s=(a->nxt)->nxt;
  40. if(a==NULL||u==NULL||s==NULL)
  41. break;
  42. t=s->nxt;
  43. s->nxt=u;
  44. u->nxt=a;
  45. a->nxt=t;
  46. a=t;
  47.  
  48. };
  49. a=head;
  50. for(int j=0;j<9;j++)
  51. {
  52. cout<<a->i<<"->";
  53. a=a->nxt;
  54. }
  55. return 0;
  56. }
Runtime error #stdin #stdout 0s 2988KB
stdin
1
2
3
4
5
6
7
8
stdout
Standard output is empty