Where did it go?

Trying to understand this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Get number
	cin >> dPhone;
	
	//Show information at index and "delete an entry." 
	while( index < size && !found )
	{
		if(tele[index].phone.compare(dPhone)== 0)
		{
			cout << "--Deleting--" << endl;
			cout << endl;
			cout << tele[index].lname << endl;
			cout << tele[index].fname << endl;
			cout << tele[index].streetAdd << endl;
			cout << tele[index].cityStateZ << endl;
			cout << tele[index].phone << endl;
			cout << endl;
		//To "remove" element.
			//This is just to see what it is before
			for(int i = 0; i < size; i++)
			{
			cout << tele[i].lname << endl;
			cout << tele[i].fname << endl;
			cout << tele[i].streetAdd << endl;
			cout << tele[i].cityStateZ << endl;
			cout << tele[i].phone << endl;
				
			}
			
			//The mystery
			--size;
			tele[index] = tele[size];
			
			//To see after
			for(int j= 0; j < index; j++)
			{
			
				cout << endl;
			cout << tele[j].lname << endl;
			cout << tele[j].fname << endl;
			cout << tele[j].streetAdd << endl;
			cout << tele[j].cityStateZ << endl;
			cout << tele[j].phone << endl;
			}
			
			
			
			found = true;
	     }
			else if(!found)
			index++;
	}


The original array has smith,lauren, cory,walter, jack. When I do the cout before the part I don't understand I get smith, lauren, cory ,walter,jack.Now say I delete walter. When I do the cout after I get ..smith lauren, jack.

If you notice that is 3. When I display in a different function. I get jack, lauren, cory, smith (this is corret)

The code works but I"m trying to understand how it is working. What is happening in the middle part. And how is it correct at the end//?
thanks

edit;;;;i made the second loop <size and I see everything. But still dont understand
Last edited on
Topic archived. No new replies allowed.