• Home
  • Blog
  • Questions 1-7 are based on the following program, #include using namespace std; class cList { public: cList(); ~cList(); cList(int n); int getNum(); cList *previous; cList *next; …

Questions 1-7 are based on the following program, #include using namespace std; class cList { public: cList(); ~cList(); cList(int n); int getNum(); cList *previous; cList *next; …

0 comments

Questions 1-7 are based on the following program,

#include [removed]

using namespace std;

class cList {
public:
cList();
~cList();
cList(int n);
int getNum();

cList *previous;
cList *next;

private:
int num;
};

cList::cList() // Question c).

cList::~cList() { } // Question d).

cList::cList(int n) // Question e).

int cList::getNum() {
return num;
}

int function1(int m) {
return (m%3);
}

int main() {
cList *p1 = new cList(21);
cList *p2 = new cList(3);
cList *p3 = new cList(80);
cList *p4 = new cList(16);

p1→previous = p4;
p1→next = p2;

p2→previous = p1;
p2→next = p3;

p3→previous = p2;
p3→next = p4;

p4→next = p1;
p4→previous = p3;

cList *current = p3;

while (current→next != p3) {
cout << function1(current→getNum()) << “n”;
current = current→next;
}

while (current→previous != p2) {
cout << function1(current→getNum()) << “n”;
for (int i=0; i[removed]= 1.
c. Implement a function that returns the value of the nth number in this sequence.

9. Suppose there are seven players playing Halo3. They are CatchMeIfYouCan, Halo4, Fake1, SweetGirl, NaughtyBoy, GoldenFinger, and FireBall. Their scores are as indicated in the following Table 1,

Name Score
CatchMeIfYouCan 1500
Halo4 3500
Fake1 1000
SweetGirl 2200
NaughtyBoy 1960
GoldenFinger 12900
FireBall 5800

Table 1. Players and Scores

Now use BubbleSort algorithm to sort the players in the descending order of their scores. Write down/ draw the table of each intermediate step/ round and determine how many steps/ rounds BubbleSort uses totally. (15 points)

CatchMeIfYouCan
Halo4
Fake1
SweetGirl

NaughtyBoy
GoldenFinger
FireBall
GoldenFinger
CatchMeIfYouCan
Halo4
Fake1

SweetGirl
NaughtyBoy
FireBall
GoldenFinger
FireBall
CatchMeIfYouCan
Halo4

Fake1
SweetGirl
NaughtyBoy
GoldenFinger
FireBall
Halo4
CatchMeIfYouCan
SweetGirl
Fake1
NaughtyBoy

GoldenFinger
FireBall
Halo4
SweetGirl

CatchMeIfYouCan
NaughtyBoy
Fake1
GoldenFinger
FireBall
Halo4
SweetGirl
NaughtyBoy
CatchMeIfYouCan
Fake1

10. (Bonus points) Is there repetitive/ unnecessary step/ round in the above BubbleSort? If there is, how will you suggest avoiding repetitive/ unnecessary step/ round in the BubbleSort algorithm? (10 points)

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}