SelectionSortTypleImp

Having issues with my bool selectionSortType::equalList(const selectionSortType& otherList) const section and can't figure out what is wrong

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//Implementation File for the class selectionSortType
    
#include <ostream>
#include "selectionSortType.h" 

using namespace std;

void selectionSortType::setUnsortedList (const int list[], int size)
{
	   elementsInList=size;
   for(int i=0;i<elementsInList;i++)
       unsortedList[i]=list[i];
   sortList();
}

void selectionSortType::getUnsortedList(int list[], int& size) const
{
	   size=elementsInList;
   for(int i=0;i<elementsInList;i++)
       list[i]=unsortedList[i];
}

void selectionSortType::getSortedList(int list[], int& size) const
{
	   size=elementsInList;
   for(int i=0;i<elementsInList;i++)
       list[i]=sortedList[i];
}

int selectionSortType::getLargestElement() const
{
	   return sortedList[elementsInList-1];
}

int selectionSortType::getSmallestElement() const
{
	   return sortedList[0];
}

float selectionSortType::getAverage() const
{
	int sum=0;
float average;
for(int i=0;i<elementsInList;i++)
       sum=sum+ unsortedList[i];
average=(float)sum/elementsInList;
return average;
}

void selectionSortType::printUnsortedList(ostream& output) const
{
	   for(int i=0;i<elementsInList;i++)
       output<<" "<<unsortedList[i];
}


void selectionSortType::printSortedList(ostream& output) const
{
	   for(int i=0;i<elementsInList;i++)
       output<<" "<<sortedList[i];
}

bool selectionSortType::equalList(const selectionSortType& otherList) const
{
	   if(elementsInList!=otherList.elementsInList)
       return false;
   for(int i=0;i<elementsInList;i++)
   {
   if(sortedList[i]!=otherList.sortedList[i])
       return false;
   }
   return true;
}

selectionSortType::selectionSortType(const int list[], int size)
{
	   elementsInList=size;
   for(int i=0;i<elementsInList;i++)
       unsortedList[i]=list[i];
   sortList();
}

selectionSortType::selectionSortType()  //default constructor
{
   elementsInList=0;
   for(int i=0;i<elementsInList;i++)
       unsortedList[i]=0;
}

void selectionSortType::sortList() 
{
	   int i,j,temp,min,loc;
   for(i=0;i<elementsInList;i++)
       sortedList[i]=unsortedList[i];
   for(i=0;i<elementsInList-1;i++)
       {
       min=sortedList[i];
       loc=i;
       for(j=i+1;j<elementsInList;j++)
           {
           if(sortedList[j]<min)
               {
               min=sortedList[j];
               loc=j;
               }
           }
       temp=sortedList[i];
       sortedList[i]=sortedList[loc];
       sortedList[loc]=temp;
       }
}
Topic archived. No new replies allowed.