fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct node{
  4. int data;
  5. struct node *link;
  6. };
  7.  
  8. struct node* push(struct node *h,int n){
  9. struct node *temp=new node;
  10. struct node *first=h;
  11. for(int i=0;i<n;++i){
  12. int x;
  13. cin>>x;
  14. if(h==Null){
  15. h=temp;
  16. h->data=x;
  17. h=h->link;}
  18. else
  19. {
  20. h->data=x;
  21. h=h->link;
  22. }
  23.  
  24. }
  25. h->link=Null;
  26. return first;
  27. }
  28.  
  29.  
  30. void reverse(struct node *h,int k,int n){
  31. struct node *p=h;
  32. struct node *q=h->link;
  33. for(int i=0;i<n/2;++i){
  34. p->link=q->link;
  35. q=q->link;
  36. for(int i=0;i<k;++i){
  37. p=p->link;
  38. q=q->link;
  39. }
  40.  
  41. }}
  42. void print(struct node *head){
  43. while(head!=Null){
  44. cout<<head->data<<" ";
  45. head=head->link;
  46. }}
  47. int main() {
  48. struct node *head;
  49. head=Null;
  50. int n,k;
  51. cin>>n,k;
  52. head=push(head,n);
  53. reverse(head,k,n);
  54. print(head);
  55.  
  56. // your code goes here
  57. return 0;
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
2
1 2 3 4
compilation info
prog.cpp: In function ‘node* push(node*, int)’:
prog.cpp:14:9: error: ‘Null’ was not declared in this scope
   if(h==Null){
         ^~~~
prog.cpp:25:10: error: ‘Null’ was not declared in this scope
  h->link=Null;
          ^~~~
prog.cpp: In function ‘void print(node*)’:
prog.cpp:43:14: error: ‘Null’ was not declared in this scope
  while(head!=Null){
              ^~~~
prog.cpp: In function ‘int main()’:
prog.cpp:49:6: error: ‘Null’ was not declared in this scope
 head=Null;
      ^~~~
stdout
Standard output is empty