answersLogoWhite

0

#include<stdio.h>

#include<conio.h>

#define null 0

void create();

void display();

void insert();

void delet();

void erase();

void create2();

void display2();

void insert2();

void delet2();

void erase2();

void link1();

void link2();

void merge();

struct node

{

int info;

struct node *next;

}*start,*ptr,*temp,*prev;

struct node2

{

int info;

struct node2 *nex;

}*start2,*ptr2,*temp2,*prev2;

void main()

{

int op;

clrscr();

do

{

printf("\n1.link1\n2.link2\n3.merge\n4.exit");

printf("\nEnter your option");

scanf("%d",&op);

switch(op)

{

case 1:

link1();

break;

case 2:

link2();

break;

case 3:

merge();

break;

case 4:

break;

default:

printf("\nEnter correct option");

}

}while(op!=4);

getch();

}

void create()

{

int data;

printf("\nEnter the data");

scanf("%d",&data);

do

{

ptr=malloc(sizeof(struct node));

ptr->info=data;

ptr->next=NULL;

if(start==NULL)

start=ptr;

else

{

temp=start;

while(temp->next!=NULL)

{

temp=temp->next;

}

temp->next=ptr;

}

printf("\nEnter the data & Press 0 to terminate");

scanf("%d",&data);

}while(data!=0);

}

void display()

{

temp=start;

if(start==NULL)

printf("\nList is empty");

else

{

printf("\nElements of list:\n");

while(temp->next!=NULL)

{

printf("%d\t",temp->info);

temp=temp->next;

}

printf("%d\t",temp->info);

}

}

void insert()

{

int data,pos;

printf("\nEnter data & position to insert the element");

scanf("d",&data,&pos);

temp=start;

ptr=malloc(sizeof(struct node));

ptr->info=data;

while(temp->next!=NULL)

{

if(temp->info==pos)

{

ptr->next=temp->next;

temp->next=ptr;

break;

}

else

temp=temp->next;

}

if(temp->next==NULL)

{

temp->next=ptr;

ptr->next=NULL;

}

}

void delet()

{

int pos,flag=0;

if(start==NULL)

printf("List is empty");

else

{

printf("Enter element to be deleted");

scanf("%d",&pos);

temp=start;

if(start->info==pos)

{

flag=1;

start=start->next;

free(temp);

}

else

{

while(temp->next!=NULL)

{

prev=temp;

temp=temp->next;

if(temp->info==pos)

{

flag=1;

prev->next=temp->next;

free(temp);

break;

}

}

}

if(flag==0)

printf("\nElement is not present in list");

}

}

void erase()

{

if(start==NULL)

printf("\nList is empty");

else

{

while(start->next!=NULL)

{

temp=start;

start=start->next;

free(temp);

}

temp=start;

start=start->next;

free(temp);

printf("list is erased");

}

}

void create2()

{

int data;

printf("\nEnter the data");

scanf("%d",&data);

do

{

ptr2=malloc(sizeof(struct node2));

ptr2->info=data;

ptr2->nex=NULL;

if(start2==NULL)

start2=ptr2;

else

{

temp2=start2;

while(temp2->nex!=NULL)

{

temp2=temp2->nex;

}

temp2->nex=ptr2;

}

printf("\nEnter the data & Press 0 to terminate");

scanf("%d",&data);

}while(data!=0);

}

void display2()

{

temp2=start2;

if(start2==NULL)

printf("\nList is empty");

else

{

printf("\nElements of list:\n");

while(temp2->nex!=NULL)

{

printf("%d\t",temp2->info);

temp2=temp2->nex;

}

printf("%d\t",temp2->info);

}

}

void insert2()

{

int data,pos;

printf("\nEnter data & position to insert the element");

scanf("d",&data,&pos);

temp2=start2;

ptr2=malloc(sizeof(struct node2));

ptr2->info=data;

while(temp2->nex!=NULL)

{

if(temp2->info==pos)

{

ptr2->nex=temp2->nex;

temp2->nex=ptr2;

break;

}

else

temp2=temp2->nex;

}

if(temp2->nex==NULL)

{

temp2->nex=ptr2;

ptr2->nex=NULL;

}

}

void delet2()

{

int pos,flag=0;

if(start2==NULL)

printf("List is empty");

else

{

printf("Enter element to be deleted");

scanf("%d",&pos);

temp2=start2;

if(start2->info==pos)

{

flag=1;

start2=start2->nex;

free(temp2);

}

else

{

while(temp2->nex!=NULL)

{

prev2=temp2;

temp2=temp2->nex;

if(temp2->info==pos)

{

flag=1;

prev2->nex=temp2->nex;

free(temp2);

break;

}

}

}

if(flag==0)

printf("\nElement is not present in list");

}

}

void erase2()

{

if(start2==NULL)

printf("\nList is empty");

else

{

while(start2->nex!=NULL)

{

temp2=start2;

start2=start2->nex;

free(temp2);

}

temp2=start2;

start2=start2->nex;

free(temp2);

printf("list is erased");

}

}

void link1()

{

int op;

start=NULL;

do

{

printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");

printf("\nEnter your option");

scanf("%d",&op);

switch(op)

{

case 1:

create();

break;

case 2:

display();

break;

case 3:

insert();

break;

case 4:

delet();

break;

case 5:

erase();

break;

case 6:

break;

default:

printf("\nEnter correct option");

}

}while(op!=6);

getch();

}

void link2()

{

int op;

start2=NULL;

do

{

printf("\n1.create\n2.display\n3.insert\n4.delete\n5.erase\n6.exit");

printf("\nEnter your option");

scanf("%d",&op);

switch(op)

{

case 1:

create2();

break;

case 2:

display2();

break;

case 3:

insert2();

break;

case 4:

delet2();

break;

case 5:

erase2();

break;

case 6:

break;

default:

printf("\nEnter correct option");

}

}while(op!=6);

getch();

}

void merge()

{

if(start==NULL)

{

start=start2;

}

else

{

temp=start;

while(temp->next!=NULL)

{

temp=temp->next;

}

temp->next=start2;

}

temp=start;

if(start==NULL)

printf("\nList is empty");

else

{

printf("\nElements of list:\n");

while(temp!=NULL)

{

printf("%d\t",temp->info);

temp=temp->next;

}

}

getch();

}

the above listed program is definitely good one, here is a program which just does merging job, http://www.refcode.net/2013/02/merging-linked-lists.html

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

Which is preferred for writing a Merge Sort routine contiguous or linked memory?

Linked memory because its very useful primarily when the lists to be sorted are very large and the size of data to be moved is small.


Where is the mail merge feature located in the main menu?

It would depend on the program you are trying to use.


What is the code for c and c plus plus program to merge two circular linked list?

Circular linked lists are really no different to ordinary linked lists, other than that the tail node points back to the head node (and vice versa if the list is doubly-linked). Therefore the merge process is exactly the same: iterate through the second list and insert each node's data into the first list. Since lists are un-associated containers, it doesn't matter where the insertions occur but, by convention, insertions typically occur at the tail of the list. If an order must be maintain, an insertion sort should be employed instead. Note that if you need to maintain the original two lists (in their un-merged state), simply copy the first and insert the second into the copy instead.


How do you merge 2 Visual C programs to get a single output?

You cannot. A C program can only have one global main function but you'd be trying to compile a program that has two main functions. The only way to merge the two programs is to modularise both programs so that neither is dependent upon their main functions. Once modularised, you can include those modules in any program. Alternatively, you can create binary libraries from the modules and link them into any program.


How do you write merge sort in Pascal?

To write a merge sort in Pascal, you need to implement a recursive function that divides the array into halves until single-element arrays are reached. Then, you merge these arrays back together in sorted order. Here's a basic structure: procedure MergeSort(var arr: array of Integer; left, right: Integer); var mid: Integer; begin if left &lt; right then begin mid := (left + right) div 2; MergeSort(arr, left, mid); MergeSort(arr, mid + 1, right); Merge(arr, left, mid, right); // You need to implement the Merge procedure end; end; You will also need to implement the Merge procedure to combine the sorted halves.

Related Questions

How to write aC program to merge two singly linked list?

write a c program to circular queue


How do you write a sentence with the word merge?

Please be very careful when you merge with traffic on the expressway.


How would you sort a linked list?

Use merge sortUse tree sort


When a program combines a document with a recipient address it is performing a?

Mail merge


When a program combines a document with a recipient address it is performing a what?

Mail merge


If WikiTree is supposed to be a single lineage-linked database why does there appear to be a tool to merge entire trees but not a tool to link individuals in other trees?

WikiTree is intended to be a single, worldwide family tree. Ideally, there should be one lineage-linked profile for every individual who ever lived. The merge tool does not merge entire trees, it merges individuals. When duplicate profiles of the same individuals are merged, they aren't just linked. They are fully combined into one profile.


Which is preferred for writing a Merge Sort routine contiguous or linked memory?

Linked memory because its very useful primarily when the lists to be sorted are very large and the size of data to be moved is small.


How write a draft of birthday invitations and use mail merge features?

&Igrave;


Where is the mail merge feature located in the main menu?

It would depend on the program you are trying to use.


Does mail merge give you the opportunity to type and create your own data?

No, but a text-editor program does.


When would a business use mail merge?

to write lots of letters to people etc


What is used to combine cells together in the program excel?

You can use the Merge and Center icon on the formatting toolbar or do it through the Format menu by going to Cells and then picking the Merge cells option.

Trending Questions
Why does the floor drain bubble when the washer drains? What is the virtual function and friend function? The operational effectiveness and operational suitability questions that must be addressed during Operational Test and Evaluation (OT and ampE) to assess the system's capability to perform its mission? Where is the condenser motor located in your home ac? What are the steps to convert a IEEE 754 binary floating point representation single precision to decimal? What is the starting salary for a Chemical Engineer in South Africa? What inventions did Andrew Carnegie make? Three bulbs of different watts are connected in series - which bulb will burn brightly - the higher wattage bulb or the lower? What are the 3 characteristics that categorize integrated circuits? Why is a handle made of metal? What is the difference between algorithm and pseudocode in computer science? How long does a programmer take to make a professional Program? A workshop designed to retrain workers 55 years of age and older who have lost their jobs is proposed. Suppose the workshop will increase the income of each participant by 1000 per year for a period o? How does a power inverter work? What are nanopolymers? What is the meaning of UB in structural engineering? What is the analogy of drill to bore? How does electromagnetic induction produce induced current? What size wire and breaker for 125hp 240 volts 3 phase motor? What is the difference between h orizontal and vertical organizational structure?