0% found this document useful (0 votes)
5 views3 pages

Datastructure#3

The document summarizes 4 cases for deleting an item from a data structure list. Case 1 describes deleting the first item by replacing it with the last item and decreasing the length by 1. Case 2 describes deleting the last item by finding the matching key and performing the same replacement and length decrease. Case 3 describes the function exiting without changes if the item is not found. Case 4 describes deleting the first duplicate item by replacing and decreasing length, leaving the other duplicate unchanged.

Uploaded by

Mohammad Qassas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Datastructure#3

The document summarizes 4 cases for deleting an item from a data structure list. Case 1 describes deleting the first item by replacing it with the last item and decreasing the length by 1. Case 2 describes deleting the last item by finding the matching key and performing the same replacement and length decrease. Case 3 describes the function exiting without changes if the item is not found. Case 4 describes deleting the first duplicate item by replacing and decreasing length, leaving the other duplicate unchanged.

Uploaded by

Mohammad Qassas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Student Name: Mohammad Qassas

Subject: Data Structure


Professor: Hani Q. Al-Zoubi
Date: 20/11/2023

Homework#2
The “DeleteItem” function starts at the beginning of the list ( index[0] )
and moves through the elements until it finds a matching key. We have these 4
scenarios we will go through them one by one.

 Case 1: deleting the first item "Maxwell" from the list


1. At index[0] the key “Maxwell” gets match.

2. Place a copy of the last element “Hsing” into index[0] (replacing


“Maxwell”).

3. Decrease the length of the list by one so now the length = 3 .

 Case 2: deleting the last item "Hsing" from the list


1. The “DeleteItem” starts at index[0] until it locate the key “Hsing”
index[0]:no match, index[1]:no match, index[2]: no match, index[3]:
match found.

2. Place a copy of the last element “Hsing” into index[0] (replacing


itself).

3. Decrease the length of the list by one so now the length = 3 .

 Case 3: if the item we want to delete isn’t found


1. The “DeleteItem” starts at index[0] like this: index[0]:no match,
index[1]:no match, index[2]: no match, index[3]: no match.

2. After no match has been found the function simply exits without
modifying the list. The state of the list and its length remains
unchanged.
 Case 4: if there was a duplicate of the same item(e.g
"Bradley" at both index 1 and 2)
1. The “DeleteItem” starts at index[0] until it locate the key “Bradley”
index[0]:no match, index[1]: match found.
2. Place a copy of the last element “Hsing” into index[1] (replacing
“Bradley”).

4. Decrease the length of the list by one so now the length = 3 .

Note: in case 4: “Bradley” at index[2] is unchanged because


the “DeleteItem” function only removes the first occurrence
it finds during the search.

You might also like