What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

Free E-Mail Alerts

College Lab Codings/Project Codings-Download


DataStructure-Program to sort a linked list by readjusting the links.

#include <stdio.h<
#include <conio.h<
#include <alloc.h<
/* structure containing a data part and link part */
struct node
{
int data ;
struct node *link ;
} *start, *visit ;
void getdata( ) ;
void append ( struct node **q, int num ) ;
void displaylist( ) ;
void selection_sort( ) ;
void bubble_sort( ) ;
void main( )
{
getdata( ) ;
clrscr( ) ;
printf ( "\nLinked List Before Sorting:\n" ) ;
displaylist( ) ;
selection_sort( ) ;
printf ( "\nLinked List After Selection Sorting:\n" ) ;
displaylist( ) ;
getch( ) ;
getdata( ) ;
clrscr( ) ;
printf ( "\nLinked List Before Sorting:\n" ) ;
displaylist( ) ;
bubble_sort( ) ;
printf ( "\nLinked List After Bubble Sorting:\n" ) ;
displaylist( ) ;
getch( ) ;
}
void getdata( )
{
int val, n ;
char ch ;
struct node *newnode;
clrscr( ) ;
newnode = NULL ;
do
{
printf ( "\nEnter a value: " ) ;
scanf ( "%d", &val ) ;
append ( &newnode, val ) ;
printf ( "\nAny More Nodes (Y/N): " ) ;
ch = getche( ) ;
} while ( ch == 'y' || ch == 'Y' ) ;
start = newnode ;
}
/* adds a node at the end of a linked list */
void append ( struct node **q, int num )
{
struct node *temp ;
temp = *q ;
if ( *q == NULL ) /* if the list is empty, create first node */
{
*q = malloc ( sizeof ( struct node ) ) ;
temp = *q ;
}
else
{
/* go to last node */
while ( temp -< link != NULL )
temp = temp -< link ;
/* add node at the end */
temp -< link = malloc ( sizeof ( struct node ) ) ;
temp = temp -< link ;
}
/* assign data to the last node */
temp -< data = num ;
temp -< link = NULL ;
}
/* displays the contents of the linked list */
void displaylist( )
{
visit = start ;
/* traverse the entire linked list */
while ( visit != NULL )
{
printf ( "%d ", visit -< data ) ;
visit = visit -< link ;
}
}
void selection_sort( )
{
struct node *p, *q, *r, *s, *temp ;
p = r = start ;
while ( p -< link != NULL )
{
s = q = p -< link ;
while ( q != NULL )
{
if ( p -< data < q -< data )
{
if ( p -< link == q ) /* Adjacent Nodes */
{
if ( p == start )
{
p -< link = q -< link ;
q -< link = p ;
temp = p ;
p = q ;
q = temp ;
start = p ;
r = p ;
s = q ;
q = q -< link ;
}
else
{
p -< link = q -< link ;
q -< link = p ;
r -< link = q ;
temp = p ;
p = q ;
q = temp ;
s = q ;
q = q -< link ;
}
}
else
{
if ( p == start )
{
temp = q -< link ;
q -< link = p -< link ;
p -< link = temp ;
s -< link = p ;
temp = p ;
p = q ;
q = temp ;
s = q ;
q = q -< link ;
start = p ;
}
else
{
temp = q -< link ;
q -< link = p -< link ;
p -< link = temp ;
r -< link = q ;
s -< link = p ;
temp = p ;
p = q ;
q = temp ;
s = q ;
q = q -< link ;
}
}
}
else
{
s = q ;
q = q -< link ;
}
}
r = p ;
p = p -< link ;
}
}
void bubble_sort( )
{
struct node *p, *q, *r, *s, *temp ;
s = NULL ;
/* r precedes p and s points to the node up to which comparisons are to be made */
while ( s != start -< link )
{
r = p = start ;
q = p -< link ;
while ( p != s )
{
if ( p -< data < q -< data )
{
if ( p == start )
{
temp = q -< link ;
q -< link = p ;
p -< link = temp ;
start = q ;
r = q ;
}
else
{
temp = q -< link ;
q -< link = p ;
p -< link = temp ;
r -< link = q ;
r = q ;
}
}
else
{
r = p ;
p = p -< link ;
}
q = p -< link ;
if ( q == s )
s = p ;
}
}
}

technicalsymposium

Technicalsymposium.com-A Complete Website for Engineering Students & Engineering Faculties.All Useful Links & Contents Given Below

technicalsymposium

Free Email Alerts
Get free email alerts-Fresher’s Jobs/Conference/Symposium/Exams Alerts-Click here to Subscribe.

Free Event Publishing
Publish your college technical symposium/free events in our website & Attract more targeted audience- Click here to Get

Conference/Symposium
All engineering colleges /Premier Institutions (IIT,IISC,NIT,etc.,) Conferences/Workshop details-Click here to Get

Fresher’s Jobs/Scholarships Details
Freshers Software Jobs/Government Jobs and Student Internships/Scholarships Details- Click here to Get

Placement Papers
All Software Companies previous placement papers/Govt Competitive exam previous papers/Tech Materials free download-Click her to get.

Lab Programs/Lab Manuals
All Branches of Lab Programs/Lab Manuals for all branches of Engineering-Click here to Get

University Previous Question Papers
Anna university/All leading universities previous question papers year wise and Semester wise- Click here to Get

GATE Question Papers
GATE Previous Question Papers –All Branches by year wise-Click here to Get

Indian Engineering Services (IES) Question Papers
IES Previous Question Papers –All Branches by year wise-Click here to Get

Anna University Syllabus
Anna University all branches syllabues free download for all B.E(All Branches)/B.Tech(All Branches)/M.E/M.Tech/MCA/MBA- Click here to Get

GATE/ All Entrance Exam Syllabus
GATE/ All Leading Entrance Exam Syllabus free download-Click here to Get

Competitive Exam Syllabuses
Bank/Railway/SSC,all kind of Competitive Exam syllabuses free Download-Click here to get

Civil Engineering Lecture Notes
Civil engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Electronics & Communication Engineering (ECE) Lecture Notes
Electronics & Communication Engineering (ECE) by semester wise and Lab Programs/Manuals-Click here to get

Electronics & Electronics Engineering (EEE) Lecture Notes
Electronics & Electronics Engineering (EEE) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Mechanical Engineering (MECH) Lecture Notes
Mechanical Engineering (MECH) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Computer Science Engineering (CSE) Lecture Notes
Computer Science Engineering (CSE) lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Information Technology Lecture Notes
Information Technology lecture notes by semester wise and Lab Programs/Manuals-Click here to get

MCA Lecture Notes
MCA lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Automobile Engineering Lecture Notes
Automobile Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Aeronautical Engineering Lecture Notes
Aeronautical Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Bio-Medical Engineering Lecture Notes
Bio-Medical Engineering lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Bio-Technology Lecture Notes
Bio-Technology lecture notes by semester wise and Lab Programs/Manuals-Click here to get

MBA Lecture Notes
MBA lecture notes by semester wise and Lab Programs/Manuals-Click here to get

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com