Join Our Email Alerts-Subscribe
Important Note:Login & Check Your Email Inbox and Activate Confirmation Link



Enter Your Email :

Copyright Disclaimer:
Section 107 of the Copyright Act Fair Use Contents .
We are forwarding content link(s) from our website to content website & We are not serving any contents.
Main Source:Google.com.All the Content PDF link(s) is/are obtained from GoogleSearch
for the purpose of Education & Teaching Intention. Not for commercial purpose.
Technicalsymposium.com is not liable/responsible for any copyright issues.

Data Structure Programming Source Codes & Study Notes-Free Download


DataStructure-Program to reverse a linked list.

#include <stdio.h>
#include <conio.h>
#include <alloc.h>
/* structure containing a data part and link part */
struct node
{
int data ;
struct node *link ;
} ;
void addatbeg ( struct node **, int ) ;
void reverse ( struct node ** ) ;
void display ( struct node * ) ;
int count ( struct node * ) ;
void main( )
{
struct node *p ;
p = NULL ; /* empty linked list */
addatbeg ( &p, 7 ) ;
addatbeg ( &p, 43 ) ;
addatbeg ( &p, 17 ) ;
addatbeg ( &p, 3 ) ;
addatbeg ( &p, 23 ) ;
addatbeg ( &p, 5 ) ;
clrscr( ) ;
display ( p ) ;
printf ( "\nNo. of elements in the linked list = %d", count ( p ) ) ;
reverse ( &p ) ;
display ( p ) ;
printf ( "\nNo. of elements in the linked list = %d", count ( p ) ) ;
}
/* adds a new node at the beginning of the linked list */
void addatbeg ( struct node **q, int num )
{
struct node *temp ;
/* add new node */
temp = malloc ( sizeof ( struct node ) ) ;
temp -> data = num ;
temp -> link = *q ;
*q = temp ;
}
void reverse ( struct node **x )
{
struct node *q, *r, *s ;
q = *x ;
r = NULL ;
/* traverse the entire linked list */
while ( q != NULL )
{
s = r ;
r = q ;
q = q -> link ;
r -> link = s ;
}
*x = r ;
}
/* displays the contents of the linked list */
void display ( struct node *q )
{
printf ( "\n" ) ;
/* traverse the entire linked list */
while ( q != NULL )
{
printf ( "%d ", q -> data ) ;
q = q -> link ;
}
}
/* counts the number of nodes present in the linked list */
int count ( struct node * q )
{
int c = 0 ;
/* traverse the entire linked list */
while ( q != NULL )
{
q = q -> link ;
c++ ;
}
return c ;
}

 

Programming & Lab Manuals- ebooks & Codes PDF


Software Programming Study Materials PDF-Free Download



Technicalsymposium.com-All Study Materials PDF-Free Download







Technicalsymposium.com-Free Live Support-Chat with Our Experts

Official Contact: +91-9245556793 (Whatsapp Message / SMS / Voice Call)


Our Expert team is ready to answer all your questions immediately-Feel free to speak in Tamil/English.

(Example:Events info/Lecture Notes/Off-Campus & All Jobs/Projects & All education information)

Working hrs (IST): (Morning: 10:00AM-3:00 PM) and (Evening:5:00 PM to 10:00 PM)

All Latest Question & Answer Page (FAQ)-Click here