SlideShare a Scribd company logo
1 of 3
C++ help! Write a function merge that merges two lists into one, alternating ele- ments from
each list until the end of one of the lists has been reached, then append- ing the remaining
elements of the other list. For example, merging the lists containing A B C and D E F G H
should yield the list A D B E C F G H. However, do not create a third list; insert values of the
second list into the first list. Your function should not fail when one (or both) of the lists is (are)
empty. Write and test your merge function in a main function.
Please help. Thanks a ton!
Solution
hey heres the code , when you said 'lists' I used STL, if you think I need to implement linked
lists using struct then post comment.
#include <iostream>
#include <list>
using namespace std;
void merge(list<char>,list<char>);
// Simple example uses type int
int main()
{
list<char> L;
/*list 1 elements A B C */
L.push_front('A');
L.push_back('B');
L.push_back('C');
list<char> K;
/*list 2 elements D E F G H */
K.push_back('D');
K.push_back('E');
K.push_back('F');
K.push_back('G');
K.push_back('H');
cout << endl;
/*Calling merge function */
merge(L,K);
return 0;
}
void merge(list<char> A,list<char>B)
{
list<char>::iterator i;
list<char>::iterator k;
/*here it will go through loop to merge second list with first list*/
i=A.begin();
for(k=B.begin(); k!=B.end(); ++k)
{
if(i!=A.end() && k!=B.end())
{
if((++i)!=A.end())
A.insert(i,*k);Â Â /*insert function of list is used to insert element at position mentioned in first
argument i (here we first incremented i and then we check if its not end of list then insert
element)*/
else
A.push_back(*k);
}
else if(i==A.end() || k!=B.end())
{
A.push_back(*k);
}
else
break;
}
cout<<endl;
for(i=A.begin(); i != A.end(); ++i) cout << *i << " ";
}
Output : A D B E C F G H

More Related Content

Similar to C++ help! Write a function merge that merges two lists into one- alter.docx

you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfclearvisioneyecareno
 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesDataminingTools Inc
 
MS SQL SERVER: Joining Databases
MS SQL SERVER: Joining DatabasesMS SQL SERVER: Joining Databases
MS SQL SERVER: Joining Databasessqlserver content
 
MS SQLSERVER:Joining Databases
MS SQLSERVER:Joining DatabasesMS SQLSERVER:Joining Databases
MS SQLSERVER:Joining Databasessqlserver content
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfarracollection
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfmaheshkumar12354
 
A circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfA circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfaayushmaany2k14
 
15CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 315CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 3Syed Mustafa
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4Syed Mustafa
 
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdfpoblettesedanoree498
 
Link list part 1
Link list part 1Link list part 1
Link list part 1Anaya Zafar
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function KeysMicrosoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keyssdturton
 
Programming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdfProgramming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdfPRATIKSINHA7304
 
In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfEvanpZjSandersony
 
Lists can contain other lists as elements. For example the list HAIR.pdf
Lists can contain other lists as elements. For example the list HAIR.pdfLists can contain other lists as elements. For example the list HAIR.pdf
Lists can contain other lists as elements. For example the list HAIR.pdffasttracksunglass
 
When we first examined the array based and node based implementations.docx
 When we first examined the array based and node based implementations.docx When we first examined the array based and node based implementations.docx
When we first examined the array based and node based implementations.docxajoy21
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfinfo706022
 

Similar to C++ help! Write a function merge that merges two lists into one- alter.docx (20)

you will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdfyou will implement some sorting algorithms for arrays and linked lis.pdf
you will implement some sorting algorithms for arrays and linked lis.pdf
 
MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
 
MS SQL SERVER: Joining Databases
MS SQL SERVER: Joining DatabasesMS SQL SERVER: Joining Databases
MS SQL SERVER: Joining Databases
 
MS SQLSERVER:Joining Databases
MS SQLSERVER:Joining DatabasesMS SQLSERVER:Joining Databases
MS SQLSERVER:Joining Databases
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
A circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfA circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdf
 
15CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 315CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 3
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4
 
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf
–PLS write program in c++ thanxLinked List Sorting and Reversing.pdf
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
Link list part 1
Link list part 1Link list part 1
Link list part 1
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function KeysMicrosoft Excel Glossary & Keyboard Shortcuts-Function Keys
Microsoft Excel Glossary & Keyboard Shortcuts-Function Keys
 
Programming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdfProgramming in Coday we are working with singly linked lists. Las.pdf
Programming in Coday we are working with singly linked lists. Las.pdf
 
In this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdfIn this homework- you will write a program modify program you wrote in.pdf
In this homework- you will write a program modify program you wrote in.pdf
 
Lists can contain other lists as elements. For example the list HAIR.pdf
Lists can contain other lists as elements. For example the list HAIR.pdfLists can contain other lists as elements. For example the list HAIR.pdf
Lists can contain other lists as elements. For example the list HAIR.pdf
 
When we first examined the array based and node based implementations.docx
 When we first examined the array based and node based implementations.docx When we first examined the array based and node based implementations.docx
When we first examined the array based and node based implementations.docx
 
Write a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdfWrite a function to merge two doubly linked lists. The input lists ha.pdf
Write a function to merge two doubly linked lists. The input lists ha.pdf
 

More from gilliandunce53776

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxgilliandunce53776
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxgilliandunce53776
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxgilliandunce53776
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxgilliandunce53776
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxgilliandunce53776
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxgilliandunce53776
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxgilliandunce53776
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxgilliandunce53776
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxgilliandunce53776
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxgilliandunce53776
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docxgilliandunce53776
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxgilliandunce53776
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxgilliandunce53776
 

More from gilliandunce53776 (14)

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docx
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docx
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docx
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docx
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docx
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

C++ help! Write a function merge that merges two lists into one- alter.docx

  • 1. C++ help! Write a function merge that merges two lists into one, alternating ele- ments from each list until the end of one of the lists has been reached, then append- ing the remaining elements of the other list. For example, merging the lists containing A B C and D E F G H should yield the list A D B E C F G H. However, do not create a third list; insert values of the second list into the first list. Your function should not fail when one (or both) of the lists is (are) empty. Write and test your merge function in a main function. Please help. Thanks a ton! Solution hey heres the code , when you said 'lists' I used STL, if you think I need to implement linked lists using struct then post comment. #include <iostream> #include <list> using namespace std; void merge(list<char>,list<char>); // Simple example uses type int int main() { list<char> L; /*list 1 elements A B C */
  • 2. L.push_front('A'); L.push_back('B'); L.push_back('C'); list<char> K; /*list 2 elements D E F G H */ K.push_back('D'); K.push_back('E'); K.push_back('F'); K.push_back('G'); K.push_back('H'); cout << endl; /*Calling merge function */ merge(L,K); return 0; } void merge(list<char> A,list<char>B) { list<char>::iterator i; list<char>::iterator k; /*here it will go through loop to merge second list with first list*/ i=A.begin(); for(k=B.begin(); k!=B.end(); ++k) { if(i!=A.end() && k!=B.end()) { if((++i)!=A.end()) A.insert(i,*k);Â Â /*insert function of list is used to insert element at position mentioned in first argument i (here we first incremented i and then we check if its not end of list then insert element)*/ else A.push_back(*k); } else if(i==A.end() || k!=B.end()) { A.push_back(*k); } else break; }
  • 3. cout<<endl; for(i=A.begin(); i != A.end(); ++i) cout << *i << " "; } Output : A D B E C F G H