SlideShare a Scribd company logo
using Java
2015
Data Structure
Prepared by: Mahmoud Rafeek Al-farra
in Java
7. Stack and Vector
mfarra.cst.ps www.fb.com/MahmoudRFarra
Contents
Implementation Stack using Linked List
Vector and Stack Class
Introduction
Case Study: Evaluating Expressions
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Vector is a subclass of AbstractList, and Stack is a
subclass of Vector in the Java API.
 Several data structures were supported earlier,
among them the Vector and Stack classes.
For an interactive demo on how stacks work, go to
www.cs.armstrong.edu/liang/animation/web/Stack.html
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Vector is the same as ArrayList, except that it
contains synchronized methods for accessing and
modifying the vector.
 Synchronized methods can prevent data corruption
when a vector is accessed and modified by two or
more threads concurrently.
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 For the many applications that do not require
synchronization, using ArrayList is more efficient than
using Vector.
Vector Class
mfarra.cst.ps www.fb.com/MahmoudRFarra
Stack Class
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The Stack class extends Vector to provide a last-in,
first-out (LIFO) data structure
Implementation of Stack as Linked List
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A stack can be viewed as a special type of list whose
elements are accessed, inserted, and deleted only from
the end (top).
Application: Stack of Employees
mfarra.cst.ps www.fb.com/MahmoudRFarra
Employee
Class
EmpStack
Class
EmpSystem
Class
In this class we
will create an
object of
EmpStack class,
and then
manipulates the
list using all
operations.
The class of linked
list members and
operation, this class
simulate the list of
any thing, the
object of this class
will be created and
used in the class of
EmpSystem.
A self referential
class called
Employee, contains
the attributes and
behavior of any
Employee.
1
2
3
The self-referential Class
mfarra.cst.ps www.fb.com/MahmoudRFarra
1. class Employee {
2. public int salary;
3. public String name;
4. Employee next;
5. public Employee()
6. {
7. salary = 300;
8. name = "no name";
9. next = null;
10. }
11. public Employee(int salary, String name)
12. {
13. this.salary = salary;
14. this.name = name; } }
Self Study: To
convert it to generic
class, go to page 907
in our text book.
[ind, N.W]
The EmpStack Class
mfarra.cst.ps www.fb.com/MahmoudRFarra
1. class EmpStack
2. {
3. Employee Top = null;
4. int length =0;
5. //the operation of stack will be inserted here
6. }
Push Operation
mfarra.cst.ps www.fb.com/MahmoudRFarra
Top
6
Top
6
1
Top
6
1
7
POP Operation
mfarra.cst.ps www.fb.com/MahmoudRFarra
Top
6
1
7 Top
6
1
7
Create object of EmpStack
mfarra.cst.ps www.fb.com/MahmoudRFarra
1. static void Main(string[] args)
2. {
3. EmpStack stack1 = new EmpStack();
4. }
 This objet of list will be manipulated using the
operations.
Add new node to stack
mfarra.cst.ps www.fb.com/MahmoudRFarra
1. public void Push(Employee NewEmp) {
2. Employee newe = NewEmp;
3. if (Top == null) {
4. Top = newe;
5. newe.next = null; }
6. else {
7. newe.next = Top;
8. Top = newe; }
9. length++;
10. }
Delete a node from stack
mfarra.cst.ps www.fb.com/MahmoudRFarra
1. public void Pop()
2. {
3. if (Top == null)
4. // print "Stack is Empty!!"
5. else
6. {
7. Top = Top.next;
8. length--;
9. }
10.
11. }
Stack using Array List
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Since the insertion and deletion operations on a
stack are made only at the end of the stack, it is
more efficient to implement a stack with an array
list than a linked list.
Self Study: Develop our car Project to based on array list.[P. 921]
[GW, N.W]
Case Study: Evaluating Expressions
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Stacks can be used to evaluate expressions.
 How does Google evaluate an expression?
Case Study: Evaluating Expressions
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The problem can be solved using two stacks named:
1. operandStack
2. operatorStack
 Operands and operators are pushed into the stacks
before they are processed.
Case Study: Evaluating Expressions
mfarra.cst.ps www.fb.com/MahmoudRFarra
 When an operator is processed, it is popped from
operatorStack and applied to the first two operands
from operandStack (the two operands are popped
from operandStack).
 The resultant value is pushed back to operandStack.
Case Study: Evaluating Expressions
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The algorithm proceeds in two phases:
1. Phase 1: Scanning the expression
2. Phase 2: Clearing the stack
Self Study: Develop a Project to calculate the expressions.[P. 788]
[Indi, N.W]
Case Study: Evaluating Expressions
mfarra.cst.ps www.fb.com/MahmoudRFarra
using Java
2015
FB: M a h m o u d R F a r r a
YouTube: M a h m o u d R F a r
SlidesShare: mralfarra
Thank you

More Related Content

What's hot

Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureMahmoud Alfarra
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structureMahmoud Alfarra
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureMahmoud Alfarra
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
08review (1)
08review (1)08review (1)
08review (1)IIUM
 
basics of queues
basics of queuesbasics of queues
basics of queuessirmanohar
 
Stacks in data structure
Stacks  in data structureStacks  in data structure
Stacks in data structurelodhran-hayat
 
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video TutorialMarcus Biel
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4Bianca Teşilă
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | EdurekaEdureka!
 

What's hot (20)

Chapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structureChapter 4: basic search algorithms data structure
Chapter 4: basic search algorithms data structure
 
Chapter 5: linked list data structure
Chapter 5: linked list data structureChapter 5: linked list data structure
Chapter 5: linked list data structure
 
Chapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structureChapter 3: basic sorting algorithms data structure
Chapter 3: basic sorting algorithms data structure
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
08review (1)
08review (1)08review (1)
08review (1)
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
Stacks in data structure
Stacks  in data structureStacks  in data structure
Stacks in data structure
 
Java ArrayList Video Tutorial
Java ArrayList Video TutorialJava ArrayList Video Tutorial
Java ArrayList Video Tutorial
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Queue
QueueQueue
Queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Data structures and algorithms lab4
Data structures and algorithms lab4Data structures and algorithms lab4
Data structures and algorithms lab4
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Control statements
Control statementsControl statements
Control statements
 
Java Linked List Tutorial | Edureka
Java Linked List Tutorial |  EdurekaJava Linked List Tutorial |  Edureka
Java Linked List Tutorial | Edureka
 
Java - Collections
Java - CollectionsJava - Collections
Java - Collections
 
Python session 10
Python session 10Python session 10
Python session 10
 
Ds
DsDs
Ds
 

Viewers also liked

Revenue Performance Management & Email – a Powerful Duo by Kath Pay
Revenue Performance Management & Email – a Powerful Duo by Kath PayRevenue Performance Management & Email – a Powerful Duo by Kath Pay
Revenue Performance Management & Email – a Powerful Duo by Kath PayHolistic Email Marketing
 
Talk about myself fhad no name
Talk about myself fhad no nameTalk about myself fhad no name
Talk about myself fhad no nameScott Dagilis
 
Juridische tips voor Nederlandse webshops die zich op België richten
Juridische tips voor Nederlandse webshops die zich op België richtenJuridische tips voor Nederlandse webshops die zich op België richten
Juridische tips voor Nederlandse webshops die zich op België richtenBart Van Den Brande
 
Threads of Change in Marketing Communications
Threads of Change in Marketing CommunicationsThreads of Change in Marketing Communications
Threads of Change in Marketing CommunicationsRachel Reuben
 
Using OU Campus in a Luminis Portal
Using OU Campus in a Luminis PortalUsing OU Campus in a Luminis Portal
Using OU Campus in a Luminis PortalRachel Reuben
 
7 reasons why your subscribers don't respond to your email campaigns
7 reasons why your subscribers don't respond to your email campaigns7 reasons why your subscribers don't respond to your email campaigns
7 reasons why your subscribers don't respond to your email campaignsHolistic Email Marketing
 
Rapport d'activité SoFAB 2014-2015
Rapport d'activité SoFAB 2014-2015Rapport d'activité SoFAB 2014-2015
Rapport d'activité SoFAB 2014-2015TelecomValley
 
Рузан Минасян
Рузан МинасянРузан Минасян
Рузан МинасянGohar Gasparyan
 
ձայնի ընկալումը կենդանիների կողմից
ձայնի ընկալումը կենդանիների կողմիցձայնի ընկալումը կենդանիների կողմից
ձայնի ընկալումը կենդանիների կողմիցGohar Gasparyan
 
Geneva Tourism case – automated charm offensive for foreign tourists
Geneva Tourism case – automated charm offensive for foreign touristsGeneva Tourism case – automated charm offensive for foreign tourists
Geneva Tourism case – automated charm offensive for foreign touristsMichelle Dassen
 
Revue de presse Telecom Valley - Septembre 2015
Revue de presse Telecom Valley - Septembre 2015Revue de presse Telecom Valley - Septembre 2015
Revue de presse Telecom Valley - Septembre 2015TelecomValley
 
Linked List data structure
Linked List data structureLinked List data structure
Linked List data structureMarcus Biel
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Ganesh Samarthyam
 
1 intro of data structure course
1  intro of data structure course1  intro of data structure course
1 intro of data structure courseMahmoud Alfarra
 

Viewers also liked (20)

Large scale web apps
Large scale web appsLarge scale web apps
Large scale web apps
 
Revenue Performance Management & Email – a Powerful Duo by Kath Pay
Revenue Performance Management & Email – a Powerful Duo by Kath PayRevenue Performance Management & Email – a Powerful Duo by Kath Pay
Revenue Performance Management & Email – a Powerful Duo by Kath Pay
 
Talk about myself fhad no name
Talk about myself fhad no nameTalk about myself fhad no name
Talk about myself fhad no name
 
Juridische tips voor Nederlandse webshops die zich op België richten
Juridische tips voor Nederlandse webshops die zich op België richtenJuridische tips voor Nederlandse webshops die zich op België richten
Juridische tips voor Nederlandse webshops die zich op België richten
 
Threads of Change in Marketing Communications
Threads of Change in Marketing CommunicationsThreads of Change in Marketing Communications
Threads of Change in Marketing Communications
 
Cixlo
CixloCixlo
Cixlo
 
Justin Biggs.Principal,Michigan City Area Schools personalities
Justin Biggs.Principal,Michigan City Area Schools personalitiesJustin Biggs.Principal,Michigan City Area Schools personalities
Justin Biggs.Principal,Michigan City Area Schools personalities
 
Using OU Campus in a Luminis Portal
Using OU Campus in a Luminis PortalUsing OU Campus in a Luminis Portal
Using OU Campus in a Luminis Portal
 
7 reasons why your subscribers don't respond to your email campaigns
7 reasons why your subscribers don't respond to your email campaigns7 reasons why your subscribers don't respond to your email campaigns
7 reasons why your subscribers don't respond to your email campaigns
 
Rapport d'activité SoFAB 2014-2015
Rapport d'activité SoFAB 2014-2015Rapport d'activité SoFAB 2014-2015
Rapport d'activité SoFAB 2014-2015
 
Рузан Минасян
Рузан МинасянРузан Минасян
Рузан Минасян
 
Hash map
Hash mapHash map
Hash map
 
ձայնի ընկալումը կենդանիների կողմից
ձայնի ընկալումը կենդանիների կողմիցձայնի ընկալումը կենդանիների կողմից
ձայնի ընկալումը կենդանիների կողմից
 
Informatica
InformaticaInformatica
Informatica
 
Geneva Tourism case – automated charm offensive for foreign tourists
Geneva Tourism case – automated charm offensive for foreign touristsGeneva Tourism case – automated charm offensive for foreign tourists
Geneva Tourism case – automated charm offensive for foreign tourists
 
Revue de presse Telecom Valley - Septembre 2015
Revue de presse Telecom Valley - Septembre 2015Revue de presse Telecom Valley - Septembre 2015
Revue de presse Telecom Valley - Septembre 2015
 
Java IO
Java IOJava IO
Java IO
 
Linked List data structure
Linked List data structureLinked List data structure
Linked List data structure
 
Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams Productive Programming in Java 8 - with Lambdas and Streams
Productive Programming in Java 8 - with Lambdas and Streams
 
1 intro of data structure course
1  intro of data structure course1  intro of data structure course
1 intro of data structure course
 

Similar to 7 stack and vector

Learn java
Learn javaLearn java
Learn javaPalahuja
 
Struts Java I I Lecture 8
Struts  Java  I I  Lecture 8Struts  Java  I I  Lecture 8
Struts Java I I Lecture 8patinijava
 
Krazykoder struts2 interceptors
Krazykoder struts2 interceptorsKrazykoder struts2 interceptors
Krazykoder struts2 interceptorsKrazy Koder
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2Techglyphs
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperVinay Kumar
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3Naga Muruga
 
Java concurrency model - The Future Task
Java concurrency model - The Future TaskJava concurrency model - The Future Task
Java concurrency model - The Future TaskSomenath Mukhopadhyay
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in JavaMudit Gupta
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfkarymadelaneyrenne19
 
Session 4/5 working with salesforce data including LDS
Session 4/5   working with salesforce data including LDSSession 4/5   working with salesforce data including LDS
Session 4/5 working with salesforce data including LDSHamza942706
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningSyed Irtaza Ali
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3DHIRAJ PRAVIN
 

Similar to 7 stack and vector (20)

Learn java
Learn javaLearn java
Learn java
 
Java mcq
Java mcqJava mcq
Java mcq
 
Struts Java I I Lecture 8
Struts  Java  I I  Lecture 8Struts  Java  I I  Lecture 8
Struts Java I I Lecture 8
 
Krazykoder struts2 interceptors
Krazykoder struts2 interceptorsKrazykoder struts2 interceptors
Krazykoder struts2 interceptors
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
Bt0083 server side programing 2
Bt0083 server side programing  2Bt0083 server side programing  2
Bt0083 server side programing 2
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
 
Structural pattern 3
Structural pattern 3Structural pattern 3
Structural pattern 3
 
Java concurrency model - The Future Task
Java concurrency model - The Future TaskJava concurrency model - The Future Task
Java concurrency model - The Future Task
 
Best practices in Java
Best practices in JavaBest practices in Java
Best practices in Java
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Session 4/5 working with salesforce data including LDS
Session 4/5   working with salesforce data including LDSSession 4/5   working with salesforce data including LDS
Session 4/5 working with salesforce data including LDS
 
My 70-480 HTML5 certification learning
My 70-480 HTML5 certification learningMy 70-480 HTML5 certification learning
My 70-480 HTML5 certification learning
 
Java server pages
Java server pagesJava server pages
Java server pages
 
Android development training programme , Day 3
Android development training programme , Day 3Android development training programme , Day 3
Android development training programme , Day 3
 
java_inheritance.pdf
java_inheritance.pdfjava_inheritance.pdf
java_inheritance.pdf
 

More from Mahmoud Alfarra

Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Mahmoud Alfarra
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using JavaMahmoud Alfarra
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structureMahmoud Alfarra
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structureMahmoud Alfarra
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structureMahmoud Alfarra
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structureMahmoud Alfarra
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_csMahmoud Alfarra
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structureMahmoud Alfarra
 
8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011Mahmoud Alfarra
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011Mahmoud Alfarra
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-Mahmoud Alfarra
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011Mahmoud Alfarra
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011Mahmoud Alfarra
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computerMahmoud Alfarra
 
2 programming-using-java how to built application
2 programming-using-java how to built application2 programming-using-java how to built application
2 programming-using-java how to built applicationMahmoud Alfarra
 
1 programming-using-java -introduction
1 programming-using-java -introduction1 programming-using-java -introduction
1 programming-using-java -introductionMahmoud Alfarra
 
تلخيص النصوص تلقائيا
تلخيص النصوص تلقائياتلخيص النصوص تلقائيا
تلخيص النصوص تلقائياMahmoud Alfarra
 
4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميزMahmoud Alfarra
 

More from Mahmoud Alfarra (20)

Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java - part 2
 
Computer Programming, Loops using Java
Computer Programming, Loops using JavaComputer Programming, Loops using Java
Computer Programming, Loops using Java
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Chapter 7: Queue data structure
Chapter 7:  Queue data structureChapter 7:  Queue data structure
Chapter 7: Queue data structure
 
Chapter 6: stack data structure
Chapter 6:  stack data structureChapter 6:  stack data structure
Chapter 6: stack data structure
 
Chapter 2: array and array list data structure
Chapter 2: array and array list  data structureChapter 2: array and array list  data structure
Chapter 2: array and array list data structure
 
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter1  intro toprincipleofc#_datastructure_b_csChapter1  intro toprincipleofc#_datastructure_b_cs
Chapter1 intro toprincipleofc#_datastructure_b_cs
 
Chapter 0: introduction to data structure
Chapter 0: introduction to data structureChapter 0: introduction to data structure
Chapter 0: introduction to data structure
 
3 classification
3  classification3  classification
3 classification
 
8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011
 
7 programming-using-java decision-making220102011
7 programming-using-java decision-making2201020117 programming-using-java decision-making220102011
7 programming-using-java decision-making220102011
 
6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-6 programming-using-java decision-making20102011-
6 programming-using-java decision-making20102011-
 
5 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop201020115 programming-using-java intro-tooop20102011
5 programming-using-java intro-tooop20102011
 
4 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava201020114 programming-using-java intro-tojava20102011
4 programming-using-java intro-tojava20102011
 
3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer3 programming-using-java introduction-to computer
3 programming-using-java introduction-to computer
 
2 programming-using-java how to built application
2 programming-using-java how to built application2 programming-using-java how to built application
2 programming-using-java how to built application
 
1 programming-using-java -introduction
1 programming-using-java -introduction1 programming-using-java -introduction
1 programming-using-java -introduction
 
تلخيص النصوص تلقائيا
تلخيص النصوص تلقائياتلخيص النصوص تلقائيا
تلخيص النصوص تلقائيا
 
4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز4×4×4 لتحصيل التميز
4×4×4 لتحصيل التميز
 

Recently uploaded

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfYibeltalNibretu
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resourcesaileywriter
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 

Recently uploaded (20)

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 

7 stack and vector

  • 1. using Java 2015 Data Structure Prepared by: Mahmoud Rafeek Al-farra in Java 7. Stack and Vector
  • 2. mfarra.cst.ps www.fb.com/MahmoudRFarra Contents Implementation Stack using Linked List Vector and Stack Class Introduction Case Study: Evaluating Expressions
  • 3. Introduction mfarra.cst.ps www.fb.com/MahmoudRFarra  Vector is a subclass of AbstractList, and Stack is a subclass of Vector in the Java API.  Several data structures were supported earlier, among them the Vector and Stack classes. For an interactive demo on how stacks work, go to www.cs.armstrong.edu/liang/animation/web/Stack.html
  • 4. Introduction mfarra.cst.ps www.fb.com/MahmoudRFarra  Vector is the same as ArrayList, except that it contains synchronized methods for accessing and modifying the vector.  Synchronized methods can prevent data corruption when a vector is accessed and modified by two or more threads concurrently.
  • 5. Introduction mfarra.cst.ps www.fb.com/MahmoudRFarra  For the many applications that do not require synchronization, using ArrayList is more efficient than using Vector.
  • 7. Stack Class mfarra.cst.ps www.fb.com/MahmoudRFarra  The Stack class extends Vector to provide a last-in, first-out (LIFO) data structure
  • 8. Implementation of Stack as Linked List mfarra.cst.ps www.fb.com/MahmoudRFarra  A stack can be viewed as a special type of list whose elements are accessed, inserted, and deleted only from the end (top).
  • 9. Application: Stack of Employees mfarra.cst.ps www.fb.com/MahmoudRFarra Employee Class EmpStack Class EmpSystem Class In this class we will create an object of EmpStack class, and then manipulates the list using all operations. The class of linked list members and operation, this class simulate the list of any thing, the object of this class will be created and used in the class of EmpSystem. A self referential class called Employee, contains the attributes and behavior of any Employee. 1 2 3
  • 10. The self-referential Class mfarra.cst.ps www.fb.com/MahmoudRFarra 1. class Employee { 2. public int salary; 3. public String name; 4. Employee next; 5. public Employee() 6. { 7. salary = 300; 8. name = "no name"; 9. next = null; 10. } 11. public Employee(int salary, String name) 12. { 13. this.salary = salary; 14. this.name = name; } } Self Study: To convert it to generic class, go to page 907 in our text book. [ind, N.W]
  • 11. The EmpStack Class mfarra.cst.ps www.fb.com/MahmoudRFarra 1. class EmpStack 2. { 3. Employee Top = null; 4. int length =0; 5. //the operation of stack will be inserted here 6. }
  • 14. Create object of EmpStack mfarra.cst.ps www.fb.com/MahmoudRFarra 1. static void Main(string[] args) 2. { 3. EmpStack stack1 = new EmpStack(); 4. }  This objet of list will be manipulated using the operations.
  • 15. Add new node to stack mfarra.cst.ps www.fb.com/MahmoudRFarra 1. public void Push(Employee NewEmp) { 2. Employee newe = NewEmp; 3. if (Top == null) { 4. Top = newe; 5. newe.next = null; } 6. else { 7. newe.next = Top; 8. Top = newe; } 9. length++; 10. }
  • 16. Delete a node from stack mfarra.cst.ps www.fb.com/MahmoudRFarra 1. public void Pop() 2. { 3. if (Top == null) 4. // print "Stack is Empty!!" 5. else 6. { 7. Top = Top.next; 8. length--; 9. } 10. 11. }
  • 17. Stack using Array List mfarra.cst.ps www.fb.com/MahmoudRFarra  Since the insertion and deletion operations on a stack are made only at the end of the stack, it is more efficient to implement a stack with an array list than a linked list. Self Study: Develop our car Project to based on array list.[P. 921] [GW, N.W]
  • 18. Case Study: Evaluating Expressions mfarra.cst.ps www.fb.com/MahmoudRFarra  Stacks can be used to evaluate expressions.  How does Google evaluate an expression?
  • 19. Case Study: Evaluating Expressions mfarra.cst.ps www.fb.com/MahmoudRFarra  The problem can be solved using two stacks named: 1. operandStack 2. operatorStack  Operands and operators are pushed into the stacks before they are processed.
  • 20. Case Study: Evaluating Expressions mfarra.cst.ps www.fb.com/MahmoudRFarra  When an operator is processed, it is popped from operatorStack and applied to the first two operands from operandStack (the two operands are popped from operandStack).  The resultant value is pushed back to operandStack.
  • 21. Case Study: Evaluating Expressions mfarra.cst.ps www.fb.com/MahmoudRFarra  The algorithm proceeds in two phases: 1. Phase 1: Scanning the expression 2. Phase 2: Clearing the stack Self Study: Develop a Project to calculate the expressions.[P. 788] [Indi, N.W]
  • 22. Case Study: Evaluating Expressions mfarra.cst.ps www.fb.com/MahmoudRFarra
  • 23. using Java 2015 FB: M a h m o u d R F a r r a YouTube: M a h m o u d R F a r SlidesShare: mralfarra Thank you