Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Print reverse linked list

Posted By: Adam Evans     Category: C Programming     Views: 4614

Write a program to print reverse linked list.

Code for Print reverse linked list in C Programming

#include<stdio.h>
#include<conio.h>
struct node
{
    int no;

    struct node *next;
};
    struct node *head;
    struct node  *p;
    struct node *temp;
    int ch1;

void main()
{


    int ctr,num;
    int arr[20],tempctr;
    char ch;

    clrscr();


    head = (struct node *)malloc(sizeof(struct node));

    printf("\nEnter the no::");
    flushall();
    scanf("%d",&head->no);

    printf("\nDo u want to create another node::");
    flushall();
    scanf("%c",&ch);

    p=head;
    while(ch=='y' || ch=='Y')
    {
        p->next=(struct node *)malloc(sizeof(struct node));
        p=p->next;

        printf("\nEnter the no::");
        flushall();
        scanf("%d",&p->no);

        printf("\nDo u want to create another node::");
        flushall();
        scanf("%c",&ch);
    }
    p->next=NULL;

    temp=head;
    ctr=0;
    while(temp!=NULL)
    {
        arr[ctr]=temp->no;
        ctr++;
        temp=temp->next;
    }
    tempctr=ctr;
    for(ctr=tempctr-1;ctr>=0;ctr--)
    {
        printf("\n%d",arr[ctr]);
    }
    getch();
}
  
Share: 


Didn't find what you were looking for? Find more on Print reverse linked list Or get search suggestion and latest updates.

Adam Evans
Adam Evans author of Print reverse linked list is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!