back to normal after sorting

Hello Good day to all.
I have a problem with the sorting. After sorting, and view the arrays I get a jumbled data array. How can I return it to the normal arrangement. I want to use sort for viewing only.
Cheers,
Karl



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
52
53
54
55
//****************************sbill
void sbill ()
{
long int x;
long int _cid;
char     _ln[20];
char     _fn[20];
char     _addr[40];
int sans; //selection sort
long int arraysize;
arraysize=ctr+1;
long int pass, pos, temp;
for (pass=0; pass<arraysize-1;pass++)
						{for (pos=pass+1;pos<arraysize;pos++)
							{
					       if (customer[pass].bill>customer[pos].bill)
                      {
                      strcpy(_ln , customer[pos].ln);
		   strcpy(customer[pos].ln , customer[pass].ln);
		  strcpy(customer[pass].ln , _ln);

                      strcpy(_fn , customer[pos].fn);
		   strcpy(customer[pos].fn , customer[pass].fn);
		  strcpy(customer[pass].fn , _fn);

                            temp = customer[pos].mi;
			       customer[pos].mi = customer[pass].mi;
		       	customer[pass].mi = temp;

                    strcpy(_addr , customer[pos].addr);
		 strcpy(customer[pos].addr , customer[pass].addr);
		strcpy(customer[pass].addr , _addr);

                            temp = customer[pos].prev;
			     customer[pos].prev = customer[pass].prev;
             customer[pass].prev = temp;

                            temp = customer[pos].curr;
		        customer[pos].curr = customer[pass].curr;
             customer[pass].curr = temp;

                            temp = customer[pos].bill;
              customer[pos].bill = customer[pass].bill;
			    customer[pass].bill = temp;

			}}}cout << "|Previos| |Last Name| |First Name| |MI| |address| |Curr| |Bill|\n";
for (x=1;x<=ctr;x++)
{
cout <<customer[x].ln<<" "<<customer[x].fn<<" "<<customer[x].mi<<" ";
cout <<customer[x].addr<<customer[x].prev<<" "<<" "<<customer[x].curr<<" ";
cout <<customer[x].bill<<"\n";
}
getch  ();
}
//****************************end sbill 
You will need another array to sort, so that you don't change the original array. The other array can be an array of char* or int indices into the original array if you want to make things simple.

You'll need to first initialize the proxy array so that each char* or index points to its unsorted counterpart in the original array. Then sort the proxy array. Print. Delete.

Hope this helps.
Hello Duoas,

Thank you I will try

Karl
Topic archived. No new replies allowed.