What's New-Given Below
technicalsymposium
technicalsymposium
technicalsymposium

Free E-Mail Alerts

College Lab Codings/Project Codings-Download


DataStructure-Program to merge two 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 add ( struct node **, int ) ;
void display ( struct node * ) ;
int count ( struct node * ) ;
void merge ( struct node *, struct node *, struct node ** ) ;
void main( )
{
struct node *first, *second, *third ;
first = second = third = NULL ; /* empty linked lists */
add ( &first, 9 ) ;
add ( &first, 12 ) ;
add ( &first, 14 ) ;
add ( &first, 17 ) ;
add ( &first, 35 ) ;
add ( &first, 61 ) ;
add ( &first, 79 ) ;
clrscr( ) ;
printf ( "First linked list : " ) ;
display ( first ) ;
printf ( "\nNo. of elements in Linked List : %d" , count ( first ) ) ;
add ( &second, 12 ) ;
add ( &second, 17 ) ;
add ( &second, 24 ) ;
add ( &second, 36 ) ;
add ( &second, 59 ) ;
add ( &second, 64 ) ;
add ( &second, 87 ) ;
printf ( "\n\nSecond linked list : " ) ;
display ( second ) ;
printf ( "\nNo. of elements in Linked List : %d" , count ( second ) ) ;
merge ( first, second, &third ) ;
printf ( "\n\nThe merged list : " ) ;
display ( third ) ;
printf ( "\nNo. of elements in Linked List : %d", count ( third ) ) ;
}
/* adds node to an ascending order linked list */
void add ( struct node **q, int num )
{
struct node *r, *temp = *q ;
r = malloc ( sizeof ( struct node ) ) ;
r -> data = num ;
/* if list is empty or if new node is to be inserted before the first node */
if ( *q == NULL || ( *q ) -> data > num )
{
*q = r ;
( *q ) -> link = temp ;
}
else
{
/* traverse the entire linked list to search the position to insert the new node */
while ( temp != NULL )
{
if ( temp -> data < num && ( temp -> link -> data > num || temp -> link == NULL ))
{
r -> link = temp -> link ;
temp -> link = r ;
return ;
}
temp = temp -> link ; /*go to next node */
}
r -> link = NULL ;
temp -> link = 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 ;
}
/* merges the two linked lists, restricting the common elements to occur only once in the final list */
void merge ( struct node *p, struct node *q, struct node **s )
{
struct node *z ;
z = NULL ;
/* if both lists are empty */
if ( p == NULL && q == NULL )
return ;
/* traverse both linked lists till the end. If end of any one list is reached loop is terminated */
while ( p != NULL && q != NULL )
{
/* if node being added in the first node */
if ( *s == NULL )
{ *s = malloc ( sizeof ( struct node ) ) ;
z = *s ;
}
else
{
z -> link = malloc ( sizeof ( struct node ) ) ;
z = z -> link ;
}
if ( p -> data < q -> data )
{
z -> data = p -> data ;
p = p -> link ;
}
else
{
if ( q -> data < p -> data )
{
z -> data = q -> data ;
q = q -> link ;
}
else
{
if ( p -> data == q -> data )
{
z -> data = q -> data ;
p = p -> link ;
q = q -> link ;
}
}
}
}
/* if end of first list has not been reached */
while ( p != NULL )
{
z -> link = malloc ( sizeof ( struct node ) ) ;
z = z -> link ;
z -> data = p -> data ;
p = p -> link ;
}
/* if end of second list has been reached */
while ( q != NULL )
{
z -> link = malloc ( sizeof ( struct node ) ) ;
z = z -> link ;
z -> data = q -> data ;
q = q -> link ;
}
z -> link = NULL ;
}

CSE/IT/MCA Lab & Technical Programs with Answers-Given Below

Placement Training Program for Engineering Students
(Aptitude Short-Cut Training Program)
Don’t miss this opportunity & 100% Hands on & Practical Sessions Only.

technical symposium

One Day Placement Training program on “Hands on Aptitude short-cut training program & Winning Techniques of Technical/HR Round".
• BE/B.Tech(All Branches)/ME/M.Tech(All Branches)/Passed Out Students
Training Program Will be held in A/C Hall & Reg.Fee includes Course Materials & Lunch,Refreshments.
Participation Certificate Will be Issued to All Participants
Click here to View Complete Details

technical symposium
Freshers Software/Government Jobs Details
job detailsAll Government Jobs Openings
job detailsAll Software Job Openings
job detailsAll Govt/Software Intern Openings
View all Government/Software Jobs Openings job detailsjob detailsjob details



Engineering College/Universities Conference/Symposium Details
job detailsAll Engineering College/Universities Conferences Details
job detailsAll College Symposium Details
job detailsAll College Workshops/Training Program Details
View all Conference & Symposium Details job detailsjob detailsjob details



Engineering Lecture Notes /Study Materials
job detailsCSE/ECE/CIVIL/MECHANICAL Engineering (All Sem Complete Notes)
job detailsMCA/IT/Automobile Engineering (All Sem Complete Notes)
job detailsMBA/Bio-Technology/Bio-Medical Engineering (All Sem Complete Notes)
View all Departments Lecture Notes job detailsjob detailsjob details
Placement Materials with Answers
job detailsTCS/WIPRO/CTS/INFOSYS Placement Papers with Answers
job detailsAll Software Companies Technical Round Materials
job detailsFree Interview & HR Round Materials
View all Placement Materials job detailsjob detailsjob details



Technical Round Programs/Lab Programs & Manuals
job detailsJAVA/C/C++/OS Technical Round Programs with Answer
job detailsC Aptitude Round Programs with Answers
job detailsData Structure Lab & Technical Round Programs with Answers
View all Techical Round & Lab Programs job detailsjob detailsjob details



GATE Original Question Papers Details
job detailsAll Branches of GATE Papers
job detailsGATE All Branches Syllabuses
job detailsGATE Exam Complete Details
View all GATE Exam Question Papers job detailsjob detailsjob details
Anna University & All Universities Original Question papers Details
job detailsAnna University All Branches Question Papers
job detailsAll Universities All Sem Question Papers
job detailsAll University & Anna University Elective Papers Question Papers
View all Universities Question Papers job detailsjob detailsjob details



Govt Exam Original Question Papers Details
job detailsTNPSC/TET Original Question Papers
job detailsUPSC/SSC Original Question Papers
job detailsIES Question Papers
View all Govt Exam Question Papers job detailsjob detailsjob details



Govt Exam/Entrance Exam Syllabuses Details
job detailsEngineering Services Exam Syllabus-All Department
job detailsSTAFF SELECTION COMMISSION (SSC) SYLLABUS
job detailsUGC-NET/SLET Syllabuses
View all Govt Exam/Entrance Exam Syllabuses job detailsjob detailsjob details
Engineering Colleges in Tamil Nadu-Complete Details
job detailsAll Engineering Colleges Complete Details
job detailsDistrict Wise Engineering Colleges Details
job detailsAll Engineering Colleges Address & Seats Details
View all Engineering Colleges Detailsjob detailsjob detailsjob details



Universities in India-Complete Details
job detailsAll Universities in India Complete Details
job detailsAll Universities-State Wise Complete Details
job detailsUniversities Address & Seats Complete Details
View all Universities Detailsjob detailsjob detailsjob details



Paper Presentation Abstracts -Complete Details
job detailsAll Branches of Paper Abstracts
job detailsLatest Paper Abstracts
job detailsFree Download of All Abstracts
View all Paper Abstractsjob detailsjob detailsjob details

Hosting by Yahoo!

About-Us    Contact-Us    Site-map

©copyright 2009 All rights are reserved to technicalsymposium.com