Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

# data structure3.pptx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Prochain SlideShare
Data structure.pptx
Chargement dans…3
×

## Consultez-les par la suite

1 sur 32 Publicité

# data structure3.pptx

hi every one i hope you well satisfied with this slide plz support us...

hi every one i hope you well satisfied with this slide plz support us...

Publicité
Publicité

## Plus De Contenu Connexe

Publicité

### data structure3.pptx

1. 1. CS261 DATA STRUCTURES & ALGORITHMS (WEEK-3) LECTURE-5 & 6 INTRODUCTION TO DATA STRUCTURES & ALGORITHMS Lecturer Azka Aziz Azka.a@scocs.edu.pk
2. 2. Data structures & Algorithms Lecture#05 Link List(continue..)
3. 3. Course contents Link List Data Structure (Declaration, Initialization, Updating) Insert After a specific location Insert a value before a specific location Insert a value as a first item of list Delete a value from a link list
4. 4. Insert After a specific Location Insert_after (position , value) 1. If (position <= 0); then Write(“invalid position ”); [End of if structure] 2. Temp = ptfirst; 3. Repeat for I = 1,2,3…. < position 3.1.Temp = temp -> link ; 3.2.If (temp == NULL) 3.2.1. Write(“invalid position ”); 3.2.2. Return; [End of if structre of 3.2] [End of loop of step number 3] 4. Q = new node ; 5. Q -> data = value; 6. Q -> link temp -> link; 7. Temp -> link = Q; 8. Return;
5. 5. Insert After a Specific Location Insert_after (position , value) 1. If (position <= 0); then Write(“invalid position ”); [End of if structure] 2. Temp = ptfirst; 3. Repeat for I = 1,2,3…. < position 3.1. Temp = temp -> link ; 3.2. If (temp == NULL) 3.2.1. Write(“invalid position ”); 3.2.2. Return; [End of if structure of 3.2] [End of loop of step number 3] 4. Q = new node ; 5. Q -> data = value; 6. Q -> link temp -> link; 7. Temp -> link = Q; 8. Return;
6. 6. Insert a Value Before a Specific Location Insert_before (value , position ) 1. Insert position <= 0 ; then Write(“Invalid position”) Return; [ End of if structure] 2. Temp = ptfirst; 2.1. Repeat for I = 1,2,3….. <= position-1; 2.1.1. Previous = temp; 2.1.2. Temp = temp -> link; 2.1.3. If (temp == NULL) Write(“invalid position ’) Return [End if structure of step 2.1.3] [End of loop of step 2.1] 3. Temp = new node ; 4. Temp -> data = value; 5. Temp -> link = previous -> link; 6. Previous -> link = temp; 7. Return
7. 7. Insert a Value as a First List Item Insert_First(value) 1. [create a new node] temp= new node 2. temp->data = value 3. Temp-> link = ptfirst 4. Ptfirst = temp 5. Return
8. 8. Delete a Value from Link List Delete(value) 1. [inilization] Temp = ptfist ; Previous = temp; 2. Repeat while (temp != NULL) 2.1. If (temp == ptfist) then 2.1.1. If (temp == ptfirst) then Delete temp Else Previous -> link = temp -> link ; Delete -> temp; Return; [end of if-else structure of 2.1.1. ] Else Previous = temp; Temp = temp -> link; [end of if-else structure of step 2.1] [end of loop of step of 2] 3. Write(“value not found”); 4. Return;
9. 9. Data structures & Algorithms Lecture#06 Double Link List
10. 10. Course contents Doubly Link List ADT Operations Sample Code Structure of a DLL Insert value Insert first
11. 11. Insert First Insert_first(value) 1. [create new node ] Temp = new value; 2. [insert value] Temp -> data = value; 3. Temp -> prev = NULL; 4. Temp -> next = ptfirst ; 5. Ptfirst = NULL; 6. If (ptfirst -> next != NULL) Ptfirst -> next -> prev = ptfirst; [End of if-structure] 7. Return
12. 12. Double Link list NULL NULL Doubly linked list (or two way linked list) is a type of linked list with every node containing two node pointers (next, prev) instead of only one (next). Start Diagram represents a Doubly Linked List with yellow pointers representing next-link and green pointers representing previous-link.
15. 15. Doubly Linked List … Operations Operation Description Pseudocode int size(); Counts and returns the number of nodes in Doubly Linked List  Create a Node Pointer ‘temp’ and point it to ‘start’  Create an integer variable ‘count’ and assign 0 to it  Iterate temp through all nodes of list till the end of list is reached  During every iteration add one to ‘count’  Return ‘count’ when iterations are over
16. 16. Doubly Linked List … Operations Operation Description Pseudocode void print_all(); Prints all nodes’ data values  Create a node pointer ‘temp’ and point it to ‘start’ of list  Traverse through the list until ‘temp’ reaches to the end of list (NULL)  During every iteration print the ‘data’ value
17. 17. Doubly Linked List … Operations Operation Description Pseudocode void print_all_backward(); Print all nodes’ ‘data’ values in backward direction  Create a node pointer ‘temp’ and point it to ‘end’ of list  Traverse back through the list until ‘temp’ reaches to the node before the start of list (NULL)  During every iteration print the ‘data’ value
18. 18. Doubly Linked List … Operations Operation Description Pseudocode Node* search(int); Searches through the list for a Node with given value and returns its reference  Create a node pointer ‘temp’ and point it to ‘start’  Traverse through the list until either ‘temp’ reaches to the Node with given value or it reaches to the end of list (NULL)  Return the node pointer ‘temp’