Technicalsymposium


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 ;
}


Government Jobs

All State and Central Government Jobs/Railway & Bank Jobs/Alll Competitive Exams-Complete Details.

Software Jobs

Entry Level Software & IT Jobs in Chennai/Bangalore & Leading Metro Cities-Complete Details.

Conference/Symposium

Engineering Colleges & University /Premier Institute (IIT/IIM/etc.,) Events Details.

Off-Campus/Walk-in

All Software Companies & Core Companies Off-Campus Interviews & Walk-in across India-Complete Details.

All Bank Jobs

All Government Bank & Private Bank Jobs-Complete Details.

Internships

All Companies Internships-Complete Details.

IBPS

Probationary Officers/Clerk and Management Trainees & All IBPS Exams/Syllabus-Complete Details.

GATE

All Branches Syllabus & Question Papers-Free Download.

IES-Exam

Indian Engineering Services Syllabus & Question.Papers-Complete Details.

Software Program

Top Programming Source Codes/Lab Manuals with Solutions-Complete Details

Anna University

B.E/B.Tech/M.E/M.Tech/MCA/MBA Latest Syllabus & Question Papers

Scholarships

All Central & State Govt Scholarships/ International Scholarships/Merit Scholarships Details.

Placement Papers

All Companies Placement Papers with Answers - Free Download of Materials

Aptitude

All Aptitude Test Topics with Answers-Complete Details & Free Download

Technical Round Interview

All Companies Technical Round Interview Asked Questions with Answers

Certifications

All Certifications Software & All Branches Certifications-Complete Details.

Group Discussion

Group Discussion Various Topics with Valid Points-Complete Details.

HR Round

All HR Round Questions and Answers/Tips & Do's and Don'ts of HR Round.

General Job

Job Interview Tips & Do's/Dont's/Dress Codes/Body Language-Complete Details.

Placement ebooks

All Companies Placement Materials with Answers-Complete Details.

Technical Round Tips

All Kind of Technical Round Interview Tips and Answers/ Do's and Don'ts

Resume

Resume Writing Tips/Do's & Don'ts-Complete Details.

Career Pages

All MNC Companies Career Pages & Current Openings-Complete Details.

Software Projects

All Software Projects with Source Codes-Free Download & Details.

GRE

GRE Exam Procedure and Complete Details.

TOEFL

TOEFL Exam Procedure and Complete Details.

IELTS

IELTS Exam Procedure and Complete Details

SAT

SAT Exam Procedure and Complete Details

GMAT

GMAT Exam Procedure and Complete Details

MS in USA

MS in USA Procedure and Complete Details

Civil Engineering

Civil Engineering Lecture Notes for All Universities & Lab Manuals for All Semester.-Free Download

Mechanical Engineering

Mechanical Engineering Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Automobile Engineering

Automobile Engineering Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Computer Science

Computer Science Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Information Technology

Information Technology Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

MBA

MBA Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Biotechnology

Biotechnology Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Biomedical

Biomedical Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Aeronautical Engineering

Aeronautical Engineering Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download

Chemical Engineering

Chemical Engineering Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Electronics & Communication

Electronics & Communication Engineering Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Electrical & Electronics

Electrical & Electronics Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

MCA

MCA Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

B.Sc

B.Sc All Branches (Maths/Physics/Computer Science/Electronics/etc.,)-Lecture Notes-Free Download

BCA

BCA Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

BBA

BBA Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

M.Sc

M.Sc All Branches (Maths/Physics/Computer Science/Electronics/etc.,)-Lecture Notes-Free Download

M.Com

M.Com Lecture Notes for All Universities & Lab Manuals for All Semester-Free Download.

Engineering Maths

All Semester Engineering Maths (M1/M2/M3/M4/etc.,) Lecture Notes-Free Download

Engineering EBooks

All Engineering Branches of ebooks Free Download-Complete Details.

Engineering Physics

All Semester Engineering Physics Lecture Notes-Free Download

GATE Preparation Books

All Branches of GATE Free Preparation eBooks-Free Download.

Engineering Chemistry

All Semester Engineering Chemistry Lecture Notes-Free Download

Software Companies Info

All Software Companies in India - Complete Details.

Admission

Foreign Universities All Course Admission Procedures-Complete Details.

Software Ebooks

All Programming Software free Eboooks-Free Download.

Web Hosting

All Web Hosting Procedure-Complete Details.