SlideShare a Scribd company logo
1 of 3
Download to read offline
To insert an element at given position in array:
Insert(stack s1, stack s2, int value, int pos)
//Inserts a value into the array at specified position.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
for i = 1 to pos - 1 //Till the pos-1
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
s1.push(value) //Now push your element in specified position pos.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
To delete an element at given position in array:
Delete(stack s1, stack s2, int pos)
//Deletes a value into the array at specified position.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
for i = 1 to pos - 1 //Till the pos-1
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
s1.pop(value) //Now pop your element in specified position pos.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
To delete a given element in array:
DeleteVal(stack s1, stack s2, int value)
//Deletes a value from the array.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
ele = s2.peek();
while(ele != value || !s2.empty()) //Till you found the element to be deleted.
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
ele = s2.peek()
s2.pop(value) //If element is found, delete it.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
If you have any queries with this, just get back to me.
Solution
To insert an element at given position in array:
Insert(stack s1, stack s2, int value, int pos)
//Inserts a value into the array at specified position.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
for i = 1 to pos - 1 //Till the pos-1
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
s1.push(value) //Now push your element in specified position pos.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
To delete an element at given position in array:
Delete(stack s1, stack s2, int pos)
//Deletes a value into the array at specified position.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
for i = 1 to pos - 1 //Till the pos-1
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
s1.pop(value) //Now pop your element in specified position pos.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
To delete a given element in array:
DeleteVal(stack s1, stack s2, int value)
//Deletes a value from the array.
//Assume s1 is a stack which holds the values, and s2 is an empty stack.
while(!s1.empty()) //Till the stack is empty.
s2.push(s1.pop()) //Pop element from s1, and push it in s2.
//By now, all elements are placed in reverse order from s1 to s2.
ele = s2.peek();
while(ele != value || !s2.empty()) //Till you found the element to be deleted.
s1.push(s2.pop()) //Remove elements from s2, and push them to s1.
ele = s2.peek()
s2.pop(value) //If element is found, delete it.
while(!s2.empty()) //Push all the remaining elements in s2 to s1.
s1.push(s2.pop())
If you have any queries with this, just get back to me.

More Related Content

More from anuragperipheral

what ways are quorum sensing and the two component signaling system .pdf
what ways are quorum sensing and the two component signaling system .pdfwhat ways are quorum sensing and the two component signaling system .pdf
what ways are quorum sensing and the two component signaling system .pdf
anuragperipheral
 
Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
 Average.javaimport java.util.Scanner;   import java.util.Arra.pdf Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
anuragperipheral
 
Environmental contaminants of recent concern are .pdf
                     Environmental contaminants of recent concern are .pdf                     Environmental contaminants of recent concern are .pdf
Environmental contaminants of recent concern are .pdf
anuragperipheral
 
Chemical weathering is the breakdown of rock by c.pdf
                     Chemical weathering is the breakdown of rock by c.pdf                     Chemical weathering is the breakdown of rock by c.pdf
Chemical weathering is the breakdown of rock by c.pdf
anuragperipheral
 
bu puting your values in formula You need not to.pdf
                     bu puting your values in formula  You need not to.pdf                     bu puting your values in formula  You need not to.pdf
bu puting your values in formula You need not to.pdf
anuragperipheral
 

More from anuragperipheral (20)

what ways are quorum sensing and the two component signaling system .pdf
what ways are quorum sensing and the two component signaling system .pdfwhat ways are quorum sensing and the two component signaling system .pdf
what ways are quorum sensing and the two component signaling system .pdf
 
Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
 Average.javaimport java.util.Scanner;   import java.util.Arra.pdf Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
Average.javaimport java.util.Scanner;   import java.util.Arra.pdf
 
C. 0.20 M NaCl Solution C..pdf
  C. 0.20 M NaCl                                      Solution  C..pdf  C. 0.20 M NaCl                                      Solution  C..pdf
C. 0.20 M NaCl Solution C..pdf
 
yep in water which is higly polar will dissolve i.pdf
                     yep in water which is higly polar will dissolve i.pdf                     yep in water which is higly polar will dissolve i.pdf
yep in water which is higly polar will dissolve i.pdf
 
When thinking of E or Z, the first thing that com.pdf
                     When thinking of E or Z, the first thing that com.pdf                     When thinking of E or Z, the first thing that com.pdf
When thinking of E or Z, the first thing that com.pdf
 
Since it contains oxygen double bonded to a carbo.pdf
                     Since it contains oxygen double bonded to a carbo.pdf                     Since it contains oxygen double bonded to a carbo.pdf
Since it contains oxygen double bonded to a carbo.pdf
 
salicylic acid alcohol (R-OH) and carboxylic aci.pdf
                     salicylic acid alcohol (R-OH) and carboxylic aci.pdf                     salicylic acid alcohol (R-OH) and carboxylic aci.pdf
salicylic acid alcohol (R-OH) and carboxylic aci.pdf
 
no it doesnot .pdf
                     no it doesnot                                    .pdf                     no it doesnot                                    .pdf
no it doesnot .pdf
 
It would be Ruthenium (II) Sulfide Ruthenium is .pdf
                     It would be Ruthenium (II) Sulfide  Ruthenium is .pdf                     It would be Ruthenium (II) Sulfide  Ruthenium is .pdf
It would be Ruthenium (II) Sulfide Ruthenium is .pdf
 
ketones do not give tollens test.. hence no react.pdf
                     ketones do not give tollens test.. hence no react.pdf                     ketones do not give tollens test.. hence no react.pdf
ketones do not give tollens test.. hence no react.pdf
 
for IONIC the metal name followed by nonmetal io.pdf
                     for IONIC the metal name followed by nonmetal io.pdf                     for IONIC the metal name followed by nonmetal io.pdf
for IONIC the metal name followed by nonmetal io.pdf
 
pH = 4-log2.4 = 3.62 pOH 14 - pH = 14-3.62 = 10.3.pdf
                     pH = 4-log2.4 = 3.62 pOH 14 - pH = 14-3.62 = 10.3.pdf                     pH = 4-log2.4 = 3.62 pOH 14 - pH = 14-3.62 = 10.3.pdf
pH = 4-log2.4 = 3.62 pOH 14 - pH = 14-3.62 = 10.3.pdf
 
This suggest that dissociation of FeCl3 is 100 .pdf
                     This suggest that dissociation of FeCl3 is 100  .pdf                     This suggest that dissociation of FeCl3 is 100  .pdf
This suggest that dissociation of FeCl3 is 100 .pdf
 
Total probability of dot received P = (37)(78).pdf
                     Total probability of dot received P = (37)(78).pdf                     Total probability of dot received P = (37)(78).pdf
Total probability of dot received P = (37)(78).pdf
 
Environmental contaminants of recent concern are .pdf
                     Environmental contaminants of recent concern are .pdf                     Environmental contaminants of recent concern are .pdf
Environmental contaminants of recent concern are .pdf
 
C-H polar covalent bond Solution .pdf
                     C-H polar covalent bond Solution             .pdf                     C-H polar covalent bond Solution             .pdf
C-H polar covalent bond Solution .pdf
 
Their physical properties are so dofferent just because theintermole.pdf
Their physical properties are so dofferent just because theintermole.pdfTheir physical properties are so dofferent just because theintermole.pdf
Their physical properties are so dofferent just because theintermole.pdf
 
Chemical weathering is the breakdown of rock by c.pdf
                     Chemical weathering is the breakdown of rock by c.pdf                     Chemical weathering is the breakdown of rock by c.pdf
Chemical weathering is the breakdown of rock by c.pdf
 
bu puting your values in formula You need not to.pdf
                     bu puting your values in formula  You need not to.pdf                     bu puting your values in formula  You need not to.pdf
bu puting your values in formula You need not to.pdf
 
Please post the figure.SolutionPlease post the figure..pdf
Please post the figure.SolutionPlease post the figure..pdfPlease post the figure.SolutionPlease post the figure..pdf
Please post the figure.SolutionPlease post the figure..pdf
 

Recently uploaded

SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 

To insert an element at given position in arrayInsert(stack s1, s.pdf

  • 1. To insert an element at given position in array: Insert(stack s1, stack s2, int value, int pos) //Inserts a value into the array at specified position. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. for i = 1 to pos - 1 //Till the pos-1 s1.push(s2.pop()) //Remove elements from s2, and push them to s1. s1.push(value) //Now push your element in specified position pos. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) To delete an element at given position in array: Delete(stack s1, stack s2, int pos) //Deletes a value into the array at specified position. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. for i = 1 to pos - 1 //Till the pos-1 s1.push(s2.pop()) //Remove elements from s2, and push them to s1. s1.pop(value) //Now pop your element in specified position pos. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) To delete a given element in array: DeleteVal(stack s1, stack s2, int value) //Deletes a value from the array. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. ele = s2.peek(); while(ele != value || !s2.empty()) //Till you found the element to be deleted. s1.push(s2.pop()) //Remove elements from s2, and push them to s1. ele = s2.peek()
  • 2. s2.pop(value) //If element is found, delete it. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) If you have any queries with this, just get back to me. Solution To insert an element at given position in array: Insert(stack s1, stack s2, int value, int pos) //Inserts a value into the array at specified position. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. for i = 1 to pos - 1 //Till the pos-1 s1.push(s2.pop()) //Remove elements from s2, and push them to s1. s1.push(value) //Now push your element in specified position pos. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) To delete an element at given position in array: Delete(stack s1, stack s2, int pos) //Deletes a value into the array at specified position. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. for i = 1 to pos - 1 //Till the pos-1 s1.push(s2.pop()) //Remove elements from s2, and push them to s1. s1.pop(value) //Now pop your element in specified position pos. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) To delete a given element in array: DeleteVal(stack s1, stack s2, int value) //Deletes a value from the array. //Assume s1 is a stack which holds the values, and s2 is an empty stack. while(!s1.empty()) //Till the stack is empty.
  • 3. s2.push(s1.pop()) //Pop element from s1, and push it in s2. //By now, all elements are placed in reverse order from s1 to s2. ele = s2.peek(); while(ele != value || !s2.empty()) //Till you found the element to be deleted. s1.push(s2.pop()) //Remove elements from s2, and push them to s1. ele = s2.peek() s2.pop(value) //If element is found, delete it. while(!s2.empty()) //Push all the remaining elements in s2 to s1. s1.push(s2.pop()) If you have any queries with this, just get back to me.