My program is supposed to create a matrix and add edges and vertices to the matrix, but I have one function, degreeSequence( ), that takes the array sequence and is supposed to output the degree sequence of the matrix. However, when my function goes to sort it and output it, it turns all the values that are supposed to be 2 into 55. Can anyone help?
That's my function that sorts and outputs the array
thank you in advance!
Code:
int* graphType::degreeSequence()
//Function: returns array of integers representing the degree sequence for the graph
//Pre: graph and array are initialized
//Post: returns degree sequence array
{
for(int i = 0; i < numberOfVertices; i++){ //loop to order array from largest to smallest
for(int j = 1; j < numberOfVertices; j++){
if(sequence[i] < sequence[j]){
int placeholder; //holds value of sequence[i]
sequence[i] = placeholder;
sequence[i] = sequence[j];
sequence[j] = placeholder;
}
}
}
for(int i = 0; i < numberOfVertices; i++){
cout << sequence[i] << '\t';
}
cout << endl;
return 0;
}
thank you in advance!
Comment