Presentation is loading. Please wait.

Presentation is loading. Please wait.

DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.

Similar presentations


Presentation on theme: "DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE."— Presentation transcript:

1 DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Information Technology, 3’rd Semester Lecture 10: Operations of Stack

2 Outline  Implementing the Push  Implementing the Pop  Implementing the Peek  Implementing the Clear  Implementing the Printall  Emank X Mezank !!

3 Implementing the Push operation  New nodes should be inserted at the front of the list, so that they become the top of the stack. 3 Presented & Prepared by: Mahmoud R. Alfarra Top 6 61 617

4 Pseudo code of the Push operation 3 Presented & Prepared by: Mahmoud R. Alfarra Create new object If top pointer points to null top = new new.next = null Else set the new.next = top top = new size++ index++

5 Implementing the Pop operation  The removed element should be removed from the back (Top) of the list. 3 Presented & Prepared by: Mahmoud R. Alfarra Top 617 617

6 Pseudo code of the Pop operation 3 Presented & Prepared by: Mahmoud R. Alfarra If top pointer points to null print (the stack is empty) Else top = top.next top = new Size-- Index--

7 Implementing the Peek operation  The retrieved element should be element of the back (Top) of the list. 3 Presented & Prepared by: Mahmoud R. Alfarra Top 617 Top.name Top.ID Top.data…

8 Pseudo code of the Peek operation 3 Presented & Prepared by: Mahmoud R. Alfarra If top pointer points to null print (the stack is empty) Else return top

9 Implementing the Clear operation  The clearing of stack means removing all the elements, which should be done set the top points to null. 3 Presented & Prepared by: Mahmoud R. Alfarra Top 617

10 Pseudo code of the clear operation 3 Presented & Prepared by: Mahmoud R. Alfarra If top pointer points to null print (the stack is empty) Else Top = null; index = -1; size = 0;

11 Implementing the Printall operation  The Print of all elements' data of the stack means that we have to create a new pointer points every time to the next element 3 Presented & Prepared by: Mahmoud R. Alfarra Top 617

12 Pseudo code of the Printall operation 3 Presented & Prepared by: Mahmoud R. Alfarra If top pointer points to null print (the stack is empty) Else create current pointer points to top for (current = top; current!= null ; current = current.next) print current.data Depending on your understanding of the printAll() operation, write a find method which search about a specific data. HW 10.1 Depending on your understanding of the printAll() operation, write a sort method which sorts the elements of the stack based on the name field. HW 10.2

13 Function of the PrintAll operation 3 Presented & Prepared by: Mahmoud R. Alfarra public void PrintAll() { Student current; string all = "name\tage\n"; if (Top == null) Console.WriteLine("The Stack is empty!!"); else { for (current = Top; current != null; current = current.next) all = all + current.name + "\t" + current.age + "\n"; } Console.WriteLine(all); }

14 Emank X Mezank !! أعظم أسبـاب النجاة اتقِ الله

15 Next Lecture Queue


Download ppt "DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE."

Similar presentations


Ads by Google