Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C Online

#include<stdio.h>
#include<stdlib.h>
struct Node{
       int data;
       struct Node* next;
};
struct Node* Reverse(struct Node* head)
{
       struct Node*current,*prev,*next;
       current = head;
       prev= NULL;
       while(current != NULL)
       {
              next = current->next;
              current->next = prev;
              prev = current;
              current = next;
       }
       head = prev;
       return head;
}
struct Node* Insert(struct Node* head,int data)
{
     struct  Node* temp =(struct Node*)malloc(sizeof(struct Node));
       temp->data = data;
       temp->next = NULL;
       if(head == NULL)
       {
              head = temp;
              
       }
       else{
              struct Node* temp1 = head;
              while(temp1->next != NULL)
              {
                     temp1=temp1->next;
                     temp1->next = temp;
              }
       }
       return head;
}
void print(struct Node* head)
{
       while(head!=NULL)
       {
              printf("%d",head->data);
              head = head->next;
       }
       
}
int main()
{
       struct Node* head = NULL;
       head = Insert(head,2);
       print(head);
       head = Insert(head,6);
       print(head);
       head = Insert(head,8);
       print(head);
       head = Reverse(head);
      print(head);
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.