SlideShare una empresa de Scribd logo
1 de 32
DATA STRUCTURE
Chapter 5: Linked List
Prepared & Presented by
Mr. Mahmoud R. Alfarra
2011-2012
College of Science & Technology
Dep. Of Computer Science & IT
BCs of Information Technology
http://mfarra.cst.ps
Out Line
 Self- Referential class
 What is Linked List?
 Insert & delete elements
 Print data
 Sorting data
 Search about data
 Collection of linked list
2
Self- Referential class
 Self- referential class is a class which contains
an object of it self.
 These concept uses to link objects with others.
3
class Node {
private int data;
private Node next;
public Node( int d )
{
// some code
} }
next object is an
object of Node
class, so this class
is a self referential
class
What is linked list ?
4
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
 A linked list is a collection of class objects
called nodes.
 Each node is linked to its successor node in
the list using a reference to the successor
node.
 A node is made up of a field for storing data
and the field for the node reference.
 The reference to another node is called a link.
Ahmad
25 year
Developer
Elements of list ?
5
 A list or linked list composed of number of
objects of a class, if you want to develop a list
of employees, you will insert many objects of
employees to your list, and so on …
Ali
28 year
Lecturer
Ola
27 year
Designer
....
Application: List of cars
6
Car
Class
ListCar
Class
CarSystem
Class
In this class we
will create an
object of ListCar
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
CarSystem.
A self referential
class called Car,
contains the
attributes and
behavior of any
car.
1
2
3
1- Class Car
7
1. class Car
2. {
3. public int id;
4. public String location;
5. public String type;
6. public Car next;
7. public Car()
8. {
9. id = 0;
10. location = "Gaza";
11. type = "Private";
12. }
13. }
2- class ListCar
8
1. class ListCar
2. {
3. private int length ; // instance variable to count number of elements in
the list
4. public Car head; // Object will point to the first element in the list
5. public ListCar()
6. {
7. lenght = 0;
8. head = null; // initially the head points to nothing
9. }
10. // Here the manipulated operation will be developed
11. }
Create object of List Car
9
1. static void Main(string[] args)
2. {
3. ListCar list1 = new ListCar();
4. }
 This objet of list will be manipulated using the
operations.
Insert at the first position
Data 1
Head
Data 2 Data 3 Data n
…..
null
New
data
1
2
Insert at the first position
11
1. class ListCar {
2. private int lenght ;
3. public Car head;
4. public ListCar() {
5. lenght = 0;
6. head = null; }
7. public void addAtFront(Car inserted) {
8. Car newc = new Car();
9. newc = inserted;
10. newc.next = head;
11. lenght++;
12. head = newc; }
13. }
Please Note that: all codes in the
PPT files of this course are not
completely, so you must depend
on the practical files.
The current codes are only to
explain the main idea
Insert at the last position
Data 1
Front
Data 2 Data 3 Data n
…..
null
New
data
2
null
1
Back
X 1
Back
X 1
Back
X 1
Back
X
Insert at the last position
13
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void addAtFront(Car inserted) {
4. … }
5. public void addAtback(Car inserted) {
6. Car newc = new Car();
7. Car back = head;
8. while (back.next != null)
9. back = back.next;
10. back.next = newc;
11. newc.next = null;
12. length ++;
13. }
14. }
If the list is empty?
What will be do?
Delete the first elements
Data 1
Head
Data 2 Data 3 Data n
…..
null
X
Delete the first elements
15
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void addAtFront(Car inserted) {
4. … }
5. public void addAtback(Car inserted) {
6. … }
7. public void RemoveFromFront()
8. {
9. head = head.next;
10. lenght--;
11. }
12.}
Delete the last elements
Data 1
Front
Data 2 Data 3 Data n
…..
null
Back
current
×
1
2
Delete the last elements
17
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void addAtFront(Car inserted) { … }
4. public void addAtback(Car inserted) { … }
5. public void RemoveFromFront() { … }
6. public void RemoveFromback() {
7. Car current = head;
8. Car back = head.next;
9. while (back.next != null) {
10. back = back.next;
11. current = current.next; }
12. current.next = null;
13. lenght--; }
14.}
Insert a new element at
position k
Data 1
Head
Data 2 Data 3 Data n
…..
null
New
data
1
Will be inserted at position 2 (the third element)
0 1 2 n
2
×
current
Insert a new element at
position k
19
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void RemoveFromback() { …. }
4. public void addAtPosition(Car inserted, int position) {
5. Car current = head;
6. Car newc = inserted;
7. int counter =0;
8. while (counter < position) {
9. current = current.next;
10. counter++; }
11. newc.next = current.next;
12. current.next = newc;
13. lenght++; }
14.}
Insert a new element based on an
order
Data 1
Head
Data 2 Data 3 Data n
…..
null
New
data
1
Example: Will be inserted after the value x
0 1 2 n
2
×
current
Front
Insert a new element based on an
order
21
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void addAtPosition(Car inserted, int position) { … }
4. public void addAtvalue(Car inserted, int value) {
5. Car current = head;
6. Car front = head;
7. Car newc = inserted;
8. while (current.value < value) {
9. front = current;
10. current = current.next; }
11. newc.next = current;
12. front.next = newc;
13. lenght++; }
14.}
•The new element will be
inserted in its right position
based on its value.
• Note that the list is ordered.
Delete an element from
position
Data 1
Head
Data k-
1
Data k Data n
null
Current
Data
k+1
1
× ×
Front
Delete an element from
position
23
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. ….
3. public void RemovefromPosition(int position) {
4. Car current = head;
5. Car front = head;
6. int counter = 0;
7. while (counter < position) {
8. current = front;
9. front = front.next;
10. counter++; }
11. current.next = front.next;
12. lenght--; }
13.}
Practice 1: re-
code it to delete
the node which
has value x
Print the data …
24
1. class ListCar {
2. ….
3. public void PrintData() {
4. Car current = head;
5. Console.WriteLine("The Data of List are");
6. int counter = 1;
7. while (current != null) {
8. Console.WriteLine("The Data of element # "+counter);
9. Console.WriteLine("=======================");
10. Console.WriteLine("ID " + current.id);
11. Console.WriteLine("Location " + current.location);
12. Console.WriteLine("Type " + current.type);
13. Console.WriteLine("=======================");
14. current = current.next;
15. counter++; }
16. }}
Sort linked List by swapping objects
(bubble)
Data 1
Head
Data k-
1
Data k Data n
null
Data
k+1
Current
b
c d
Second
e
Temp
1
a
2
3
Data 1
Head
Data k Data k-1 Data n
null
Data
k+1
b c d e
a
4
Sort linked List by swapping objects
(bubble)
Data 1
Head
Data k-
1
Data k Data n
null
Data
k+1
Current
b
c d
Second
e
Temp
1
a
2
3
4
Node current = head;
Node temp;
for (int i = 0; i < lenght; i++) {
Car current = head;
while (current.Next != null) {
temp.data = current.Next.data;
current.Next.Value = current.Value;
current.Value = temp;
current = current.Next.Next; }
}
Sort linked List by swapping values
(bubble)
Data 1
Head
Data k-
1
Data k Data n
null
Data
k+1
Current
b
c d e
a
Front
Tempalue = Current.value;
Current.value = front.value;
Front.value = tempvalue;
. . .
Sort linked List by swapping values
(bubble)
28
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
1. class ListCar {
2. public void bubSort() {
3. for (int i = 0; i < lenght; i++) {
4. Car current = head;
5. while (current.next != null) {
6. if (current.value > current.next.value) {
7. int TempValue = current.value;
8. int TempId = current.id;
9. String TempLocation = current.location;
10. current.value = current.next.value;
11. current.id = current.next.id;
12. current.location = current.next.location;
13. current.next.value = TempValue;
14. current.next.id = TempId;
15. current.next.location = TempLocation; }
16. current = current.next; } } }
17. }
Search about data !!
1. class ListCar {
2. public Car Find(int WantedVlaue )
3. {
4. Car current = head;
5. int flag = -1;
6. while (current != null) {
7. if (current.value == WantedVlaue) {
8. flag = 1;
9. break; }
10. current = current.next; }
11. if (flag == 1)
12. return current;
13. else
14. return null; }
15. }
Collection of linked list
30
 C# contains the collection of linked list in the
name space called:
Namespace: System.Collections.Generic
 It has a full package of methods and members
to manage its data.
Case Study :using the reference
book, write a completed
application to simulate the linked
list of PCs.
Thank You …
31
Remember that: question is the key of knowledge
Ahl Eljanna 

ٍ
‫ني‬ِ
‫َم‬‫أ‬ ٍ
‫ام‬َ
‫ق‬َ
‫م‬ ِ
‫ِف‬ َ
‫ني‬ِ
‫َّق‬‫ت‬ُ
‫ْم‬‫ل‬‫ا‬ َّ
‫ن‬ِ‫إ‬
(
)::
ٍ
‫ون‬ُ‫ي‬ُ‫ع‬َ
‫و‬ ٍ
‫َّات‬‫ن‬َ
‫ج‬ ِ
‫ِف‬
::(
)
َ
‫ر‬ْ‫ب‬َ‫ت‬ْ
‫س‬ِ‫إ‬َ
‫و‬ ٍ
‫س‬ُ
‫د‬‫ن‬ُ
‫س‬ ْ
‫ن‬ِ
‫م‬ َ
‫ن‬‫و‬ُ
‫س‬َ‫ب‬ْ‫ل‬َ‫ي‬
َ
‫ني‬ِ‫ل‬ِ‫ب‬‫ا‬َ
‫ق‬َ‫ت‬ُ
‫م‬ ٍ
‫ق‬
)::(
َ
‫ذ‬َ
‫ك‬
َ
‫ك‬ِ‫ل‬
ٍ
‫ني‬ِ
‫ع‬ ٍ
‫ر‬‫و‬ُِ
‫ِب‬ ْ
‫م‬ُ
‫اه‬َ‫ن‬ْ
‫ج‬َّ
‫و‬َ
‫ز‬َ
‫و‬
)::(
ُ‫ع‬ْ
‫د‬َ‫ي‬
ِ‫اك‬َ‫ف‬ ِِّ
‫ل‬ُ
‫ك‬ِ‫ب‬ ‫ا‬َ
‫يه‬ِ‫ف‬ َ
‫ن‬‫و‬
َ
‫ني‬ِ‫ن‬ِ
‫آم‬ ٍ
‫ة‬َ
‫ه‬
)::(
32

Más contenido relacionado

La actualidad más candente

Stack Implementation
Stack ImplementationStack Implementation
Stack ImplementationZidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureZidny Nafan
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arorakulachihansraj
 
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
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structurefaran nawaz
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)Janki Shah
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesSnehilKeshari
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 

La actualidad más candente (20)

Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
stack & queue
stack & queuestack & queue
stack & queue
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Stacks
StacksStacks
Stacks
 
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
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 
Priority Queue
Priority QueuePriority Queue
Priority Queue
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Collections in .net technology (2160711)
Collections in .net technology (2160711)Collections in .net technology (2160711)
Collections in .net technology (2160711)
 
Algorithms: I
Algorithms: IAlgorithms: I
Algorithms: I
 
02 Stack
02 Stack02 Stack
02 Stack
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Control statements
Control statementsControl statements
Control statements
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 

Similar a Chapter 5: linked list data structure

القوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاالقوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاMahmoud Alfarra
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfdhavalbl38
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfrozakashif85
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxtienlivick
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfarjunhassan8
 
CH5_Linked List.ppt
CH5_Linked List.pptCH5_Linked List.ppt
CH5_Linked List.pptArifKamal36
 
CH5_Linked List.pptx
CH5_Linked List.pptxCH5_Linked List.pptx
CH5_Linked List.pptxSaralaT3
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project FileDeyvessh kumar
 

Similar a Chapter 5: linked list data structure (20)

القوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافاالقوائم المترابطة Linked List باستخدام لغة جافا
القوائم المترابطة Linked List باستخدام لغة جافا
 
Adt of lists
Adt of listsAdt of lists
Adt of lists
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
linkedlist.pptx
linkedlist.pptxlinkedlist.pptx
linkedlist.pptx
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
 
For the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdfFor the following questions, you will implement the data structure to.pdf
For the following questions, you will implement the data structure to.pdf
 
CH5_Linked List.ppt
CH5_Linked List.pptCH5_Linked List.ppt
CH5_Linked List.ppt
 
CH5_Linked List.pptx
CH5_Linked List.pptxCH5_Linked List.pptx
CH5_Linked List.pptx
 
Linked list
Linked listLinked list
Linked list
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 

Más de 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 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
 
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
 
Data preparation and processing chapter 2
Data preparation and processing chapter  2Data preparation and processing chapter  2
Data preparation and processing chapter 2Mahmoud Alfarra
 
Introduction to-data-mining chapter 1
Introduction to-data-mining  chapter 1Introduction to-data-mining  chapter 1
Introduction to-data-mining chapter 1Mahmoud Alfarra
 
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Mahmoud Alfarra
 

Más de 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 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
 
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 لتحصيل التميز
 
Data preparation and processing chapter 2
Data preparation and processing chapter  2Data preparation and processing chapter  2
Data preparation and processing chapter 2
 
Introduction to-data-mining chapter 1
Introduction to-data-mining  chapter 1Introduction to-data-mining  chapter 1
Introduction to-data-mining chapter 1
 
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
Graph-Based Technique for Extracting Keyphrases In a Single-Document (GTEK)
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Chapter 5: linked list data structure

  • 1. DATA STRUCTURE Chapter 5: Linked List Prepared & Presented by Mr. Mahmoud R. Alfarra 2011-2012 College of Science & Technology Dep. Of Computer Science & IT BCs of Information Technology http://mfarra.cst.ps
  • 2. Out Line  Self- Referential class  What is Linked List?  Insert & delete elements  Print data  Sorting data  Search about data  Collection of linked list 2
  • 3. Self- Referential class  Self- referential class is a class which contains an object of it self.  These concept uses to link objects with others. 3 class Node { private int data; private Node next; public Node( int d ) { // some code } } next object is an object of Node class, so this class is a self referential class
  • 4. What is linked list ? 4 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬  A linked list is a collection of class objects called nodes.  Each node is linked to its successor node in the list using a reference to the successor node.  A node is made up of a field for storing data and the field for the node reference.  The reference to another node is called a link.
  • 5. Ahmad 25 year Developer Elements of list ? 5  A list or linked list composed of number of objects of a class, if you want to develop a list of employees, you will insert many objects of employees to your list, and so on … Ali 28 year Lecturer Ola 27 year Designer ....
  • 6. Application: List of cars 6 Car Class ListCar Class CarSystem Class In this class we will create an object of ListCar 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 CarSystem. A self referential class called Car, contains the attributes and behavior of any car. 1 2 3
  • 7. 1- Class Car 7 1. class Car 2. { 3. public int id; 4. public String location; 5. public String type; 6. public Car next; 7. public Car() 8. { 9. id = 0; 10. location = "Gaza"; 11. type = "Private"; 12. } 13. }
  • 8. 2- class ListCar 8 1. class ListCar 2. { 3. private int length ; // instance variable to count number of elements in the list 4. public Car head; // Object will point to the first element in the list 5. public ListCar() 6. { 7. lenght = 0; 8. head = null; // initially the head points to nothing 9. } 10. // Here the manipulated operation will be developed 11. }
  • 9. Create object of List Car 9 1. static void Main(string[] args) 2. { 3. ListCar list1 = new ListCar(); 4. }  This objet of list will be manipulated using the operations.
  • 10. Insert at the first position Data 1 Head Data 2 Data 3 Data n ….. null New data 1 2
  • 11. Insert at the first position 11 1. class ListCar { 2. private int lenght ; 3. public Car head; 4. public ListCar() { 5. lenght = 0; 6. head = null; } 7. public void addAtFront(Car inserted) { 8. Car newc = new Car(); 9. newc = inserted; 10. newc.next = head; 11. lenght++; 12. head = newc; } 13. } Please Note that: all codes in the PPT files of this course are not completely, so you must depend on the practical files. The current codes are only to explain the main idea
  • 12. Insert at the last position Data 1 Front Data 2 Data 3 Data n ….. null New data 2 null 1 Back X 1 Back X 1 Back X 1 Back X
  • 13. Insert at the last position 13 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void addAtFront(Car inserted) { 4. … } 5. public void addAtback(Car inserted) { 6. Car newc = new Car(); 7. Car back = head; 8. while (back.next != null) 9. back = back.next; 10. back.next = newc; 11. newc.next = null; 12. length ++; 13. } 14. } If the list is empty? What will be do?
  • 14. Delete the first elements Data 1 Head Data 2 Data 3 Data n ….. null X
  • 15. Delete the first elements 15 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void addAtFront(Car inserted) { 4. … } 5. public void addAtback(Car inserted) { 6. … } 7. public void RemoveFromFront() 8. { 9. head = head.next; 10. lenght--; 11. } 12.}
  • 16. Delete the last elements Data 1 Front Data 2 Data 3 Data n ….. null Back current × 1 2
  • 17. Delete the last elements 17 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void addAtFront(Car inserted) { … } 4. public void addAtback(Car inserted) { … } 5. public void RemoveFromFront() { … } 6. public void RemoveFromback() { 7. Car current = head; 8. Car back = head.next; 9. while (back.next != null) { 10. back = back.next; 11. current = current.next; } 12. current.next = null; 13. lenght--; } 14.}
  • 18. Insert a new element at position k Data 1 Head Data 2 Data 3 Data n ….. null New data 1 Will be inserted at position 2 (the third element) 0 1 2 n 2 × current
  • 19. Insert a new element at position k 19 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void RemoveFromback() { …. } 4. public void addAtPosition(Car inserted, int position) { 5. Car current = head; 6. Car newc = inserted; 7. int counter =0; 8. while (counter < position) { 9. current = current.next; 10. counter++; } 11. newc.next = current.next; 12. current.next = newc; 13. lenght++; } 14.}
  • 20. Insert a new element based on an order Data 1 Head Data 2 Data 3 Data n ….. null New data 1 Example: Will be inserted after the value x 0 1 2 n 2 × current Front
  • 21. Insert a new element based on an order 21 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void addAtPosition(Car inserted, int position) { … } 4. public void addAtvalue(Car inserted, int value) { 5. Car current = head; 6. Car front = head; 7. Car newc = inserted; 8. while (current.value < value) { 9. front = current; 10. current = current.next; } 11. newc.next = current; 12. front.next = newc; 13. lenght++; } 14.} •The new element will be inserted in its right position based on its value. • Note that the list is ordered.
  • 22. Delete an element from position Data 1 Head Data k- 1 Data k Data n null Current Data k+1 1 × × Front
  • 23. Delete an element from position 23 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. …. 3. public void RemovefromPosition(int position) { 4. Car current = head; 5. Car front = head; 6. int counter = 0; 7. while (counter < position) { 8. current = front; 9. front = front.next; 10. counter++; } 11. current.next = front.next; 12. lenght--; } 13.} Practice 1: re- code it to delete the node which has value x
  • 24. Print the data … 24 1. class ListCar { 2. …. 3. public void PrintData() { 4. Car current = head; 5. Console.WriteLine("The Data of List are"); 6. int counter = 1; 7. while (current != null) { 8. Console.WriteLine("The Data of element # "+counter); 9. Console.WriteLine("======================="); 10. Console.WriteLine("ID " + current.id); 11. Console.WriteLine("Location " + current.location); 12. Console.WriteLine("Type " + current.type); 13. Console.WriteLine("======================="); 14. current = current.next; 15. counter++; } 16. }}
  • 25. Sort linked List by swapping objects (bubble) Data 1 Head Data k- 1 Data k Data n null Data k+1 Current b c d Second e Temp 1 a 2 3 Data 1 Head Data k Data k-1 Data n null Data k+1 b c d e a 4
  • 26. Sort linked List by swapping objects (bubble) Data 1 Head Data k- 1 Data k Data n null Data k+1 Current b c d Second e Temp 1 a 2 3 4 Node current = head; Node temp; for (int i = 0; i < lenght; i++) { Car current = head; while (current.Next != null) { temp.data = current.Next.data; current.Next.Value = current.Value; current.Value = temp; current = current.Next.Next; } }
  • 27. Sort linked List by swapping values (bubble) Data 1 Head Data k- 1 Data k Data n null Data k+1 Current b c d e a Front Tempalue = Current.value; Current.value = front.value; Front.value = tempvalue; . . .
  • 28. Sort linked List by swapping values (bubble) 28 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬ 1. class ListCar { 2. public void bubSort() { 3. for (int i = 0; i < lenght; i++) { 4. Car current = head; 5. while (current.next != null) { 6. if (current.value > current.next.value) { 7. int TempValue = current.value; 8. int TempId = current.id; 9. String TempLocation = current.location; 10. current.value = current.next.value; 11. current.id = current.next.id; 12. current.location = current.next.location; 13. current.next.value = TempValue; 14. current.next.id = TempId; 15. current.next.location = TempLocation; } 16. current = current.next; } } } 17. }
  • 29. Search about data !! 1. class ListCar { 2. public Car Find(int WantedVlaue ) 3. { 4. Car current = head; 5. int flag = -1; 6. while (current != null) { 7. if (current.value == WantedVlaue) { 8. flag = 1; 9. break; } 10. current = current.next; } 11. if (flag == 1) 12. return current; 13. else 14. return null; } 15. }
  • 30. Collection of linked list 30  C# contains the collection of linked list in the name space called: Namespace: System.Collections.Generic  It has a full package of methods and members to manage its data. Case Study :using the reference book, write a completed application to simulate the linked list of PCs.
  • 31. Thank You … 31 Remember that: question is the key of knowledge
  • 32. Ahl Eljanna   ٍ ‫ني‬ِ ‫َم‬‫أ‬ ٍ ‫ام‬َ ‫ق‬َ ‫م‬ ِ ‫ِف‬ َ ‫ني‬ِ ‫َّق‬‫ت‬ُ ‫ْم‬‫ل‬‫ا‬ َّ ‫ن‬ِ‫إ‬ ( ):: ٍ ‫ون‬ُ‫ي‬ُ‫ع‬َ ‫و‬ ٍ ‫َّات‬‫ن‬َ ‫ج‬ ِ ‫ِف‬ ::( ) َ ‫ر‬ْ‫ب‬َ‫ت‬ْ ‫س‬ِ‫إ‬َ ‫و‬ ٍ ‫س‬ُ ‫د‬‫ن‬ُ ‫س‬ ْ ‫ن‬ِ ‫م‬ َ ‫ن‬‫و‬ُ ‫س‬َ‫ب‬ْ‫ل‬َ‫ي‬ َ ‫ني‬ِ‫ل‬ِ‫ب‬‫ا‬َ ‫ق‬َ‫ت‬ُ ‫م‬ ٍ ‫ق‬ )::( َ ‫ذ‬َ ‫ك‬ َ ‫ك‬ِ‫ل‬ ٍ ‫ني‬ِ ‫ع‬ ٍ ‫ر‬‫و‬ُِ ‫ِب‬ ْ ‫م‬ُ ‫اه‬َ‫ن‬ْ ‫ج‬َّ ‫و‬َ ‫ز‬َ ‫و‬ )::( ُ‫ع‬ْ ‫د‬َ‫ي‬ ِ‫اك‬َ‫ف‬ ِِّ ‫ل‬ُ ‫ك‬ِ‫ب‬ ‫ا‬َ ‫يه‬ِ‫ف‬ َ ‫ن‬‫و‬ َ ‫ني‬ِ‫ن‬ِ ‫آم‬ ٍ ‫ة‬َ ‫ه‬ )::( 32