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

Slides:



Advertisements
Similar presentations
Inserting a Node into a Specified Position of a Linked List To create a node for the new item newNode = new Node(item); To insert a node between two nodes.
Advertisements

Data Structure Lecture-5
Circular Linked List. COMP104 Circular Linked List / Slide 2 Circular Linked Lists * A Circular Linked List is a special type of Linked List * It supports.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Department of Computer Science and Engineering, HKUST 1 HKUST Summer Programming Course 2008 Linked List and Namespace ~ include dynamic objects.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Computer Programming 2 Lecture 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
CS162 - Topic #11 Lecture: Recursion –Problem solving with recursion –Work through examples to get used to the recursive process Programming Project –Any.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Linked Lists Ellen Walker CPSC 201 Data Structures Hiram College.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Linked Lists part 1 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 15,16 Java’s Methods.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &
The List ADT Reading: Sections 3.2, 3.3, 3.5.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CS-2852 Data Structures LECTURE 5 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Data Structures AZHAR MAQSOOD NUST Institute of Information Technology (NIIT) Lecture 6: Linked Lists Linked List Basics.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
slides adapted from Marty Stepp and Hélène Martin
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Abstract Data Types Queues Dale Roberts, Lecturer
Programming Circular Linked List.
Presented By: Mahmoud Rafeek Alfarra
Review Deleting an Element from a Linked List Deletion involves:
Building Java Programs
Presented By: Mahmoud Rafeek Alfarra
Stack and Queue APURBO DATTA.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Chapter 16-2 Linked Structures
Introduction To Programming Information Technology , 1’st Semester
Data Structures ADT List
Data Structures ADT List
Part a: Fundamentals & Class String
Building Java Programs
Presented By: Mahmoud Rafeek Alfarra
Lecture 7: Linked List Basics reading: 16.2
Introduction To Programming Information Technology , 1’st Semester
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
Data Structures ADT List
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
CS148 Introduction to Programming II
Building Java Programs
Lecture 7: Linked List Basics reading: 16.2
CS148 Introduction to Programming II
Presented By: Mahmoud Rafeek Alfarra
Linked Lists.
Presentation transcript:

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 7: Linked List(2)

Outline  Add item in the front of linked list  Add item in the n’th place of linked list  Print the data of linked list  Delete item from the back of the linked list  Delete item from the front of the linked list  Delete the n’th item from the linked list  Emank X Mezank !!

Add item in the front of linked list  Add the new item in the front, mean that the new item will be pointed to the first one. 3 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2Data 3Data n ….. null New data Back 1

Add item in the front of linked list New.Next = first; Front = new; Size ++ 4 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2Data 3Data n ….. null New data Back 1

Add item in the n’th place of linked list  Add the new item in the n’th place, mean that the new item will be pointed to the (n)’th node and then the (n-1)’th node will be pointed to new node. 5 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2Data 3Data n ….. null New data Back 1 New node will be inserted at the 3’rd place 012n 2 ×

Add item in the n’th place of linked list New.Next = n’th_node; (n-1)’th_node.next = new; Size ++ 6 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2Data 3Data n ….. null New data Back 1 New node will be inserted at the 3’rd place 012n 2 ×

Print the data of the linked list  Once a list exists, the user can explorer it.  One of the operations performed on linked List is to prints its data.  To do this, you can declare a method that examines the head of the list is not pointing to null.  Using for loop … 7 Presented & Prepared by: Mahmoud R. Alfarra Item Current = Head; for(int i = 0; Current != null; i++) Print current.data; Current = Current.Next;

Example (Linked List of cars) 8 Presented & Prepared by: Mahmoud R. Alfarra class Car { public string name; public Car next; } Build the item list of car: 1.Which is a class of car 2.Contains the car’s data 3.Contains a variable of car to point to the next node 11

Example (Linked List of cars) 9 Presented & Prepared by: Mahmoud R. Alfarra class LinkedCar { private int length ; public Car head; public LinkedCar() { lenght = 0; head = null; }} Build the list of car : 1.Which is a management class contains 2.Length of list which begins as 0 3.A variable of car as the pointer of each node and begins as null 4.All the operations 22

Example (operations on Linked List) 10 Presented & Prepared by: Mahmoud R. Alfarra Add a new car to the linked list in the front public void addAtFront(Car inserted) { Car newc = new Car (); newc = inserted; newc.next = head; lenght++; head = newc; } In the class of management (LinkedCar), we declare all the operations as add, remove, sort, … 33 Write the methods to add a new elements in the n’th position and as the last node HW 7.1

Example (operations on Linked List) 11 Presented & Prepared by: Mahmoud R. Alfarra Print the information of the cars in the LinkedList 44 public void printCarData() { Car current = head; for (int i =0 ; current != null; i++) { Console.WriteLine("The name is "+ current.name); current = current.next; } Write the methods to print the data of i’th node HW 7.2

Example (create an object of LinkedCar) 12 Presented & Prepared by: Mahmoud R. Alfarra Create a linkedlist of cars The class of management (LinkedCar) is just a class. so, need to create object to perform the operations … 55 static void Main(string[ ] args) { LinkedCar list1 = new LinkedCar(); Car car1 = new Car(); car1.name = "Mahmoud"; list1.addAtFront(car1); Car car2 = new Car(); car2.name = "Ali"; list1.addAtFront(car2); list1.printCarData(); Console.Read(); }

Home Work 13 Presented & Prepared by: Mahmoud R. Alfarra Re-write the previous example using the windows application, as the above figure HW 7.3

Retrieve data from the linked list 14 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data k-1 Data k Data n null Back Data k+1 Current  Current = Head  For (int i = 0; Current != null ; i++)  Current = Current.Next;  return current.data

Delete an item from the linked list  Deleting an item consists of removing it from the list.  There are two main types of deletion you can perform on a list. 1. You can simply ask the class to delete an item. In this case, it is usually the item at the end that gets deleted. 2.Another technique used to delete an item consists of specifying the position of the item to be deleted. 15 Presented & Prepared by: Mahmoud R. Alfarra

Delete item from the back of the linked list  (Last-1)node.next = null  Back = (Last-1)node 16 Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2 Data n-1 Data n ….. null Back 1 × × 2

Delete item from the front of the linked list  Current = head.next  Head = current  Size Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data 2 Data n-1 Data n ….. null Back × Current

Delete the k’th item from the linked list  current = position(k-1)  current.next = position(k+1)  Size Presented & Prepared by: Mahmoud R. Alfarra Data 1 Head Data k-1 Data k Data n null Back Data k+1 1 ×× Write the methods to perform the deletion operations HW 7.4

Search about data in the linked list 19 Presented & Prepared by: Mahmoud R. Alfarra Write the methods to perform the search operations HW 7.4  Wanted data  Current = Head  For (int i = 0; Current != null && current.data != wanted ; i++)  If (current.data == wanted)  return i  break  Current = Current.Next;

Emank X Mezank !! أخي أنت حرٌّ وراء السدود..... أخي أنت حرٌّ بتلك القيود إذا كنـت بالله مستعصمـا.... فماذا يضيرك كيد العبيد؟!!

Next Lecture Sorting& Searching