0

I am very confused with ADT. I get the concept of why to use ADT, but I dont know how to implement it. The problem I have to solve is to merge 2 sorted list using ADT functions provided. The ADT functions are the functions in my header file. Here is the code I have written so far.

Sort.h

#include <iostream>

using namespace std;

class Sort{

 public:
  
  Sort( int, int );//constructor
  bool sortedIsEmpty( int ); //Determines whether sorted list is empty
  int sortedGetLength( int ); //Returns the number of items that are in list
  bool sortedInsert( int ); //Inserts newItem into correct spot in list
  int sortedRetrieve( int ); //Retreives item in list
  
 private:
   
  int lenList[];
  int list1[];
  int list2[];
  int checkList[];
  int newItem;
  int item;
  int sizeA;
  int sizeB;

};

Sort.cpp


#include "Sort.h"

int main(){

  int firstList[] = {1,3,5,9};
  int secondList[]= {2,4,6,8};

  return 0;

}

Sort::Sort(int list1[], int list2[]){

  bool a = sortedIsEmpty(list1);
  bool b = sortedIsEmpty(list2);

  if(a == false){

    int sizeA = sortedGetLength(list1);

  }else{

    int sizeA = 0;

  }

  if(b == false){

    int sizeB = sortedGetLength(list2);

  }else{

    int sizeB = 0;

  }

}

bool Sort::sortedIsEmpty(int checkList[]){

  if( checkList[0] == '\0'){

    return true;

  }else{

    return false;

  }

}

int Sort::sortedGetLength(int lenList[]){

  int count = 0;

  while(lenList != '\0'){

    count ++;

  }
 
  return count;

}

bool Sort::sortedInsert(int newItem){



}

int Sort::sortedRetrieve(int item){



}

Now im not so worried about merging the lists, I can figure that out. What I cant figure out is how do I first make a call in main to go into my Sort constructor. Second, from what I have now here is the errors I get from my compiler:

Sort.cpp:22: error: prototype for 'Sort::Sort(int*, int*)' does not match any in class 'Sort'
Sort.h:15: error: candidates are: Sort::Sort(const Sort&)
Sort.h:19: error: Sort::Sort(int, int)
Sort.cpp: In constructor 'Sort::Sort(int*, int*)':
Sort.cpp:24: error: invalid conversion from 'int*' to 'int'
Sort.cpp:24: error: initializing argument 1 of 'bool Sort::sortedIsEmpty(int)'Sort.cpp:25: error: invalid conversion from 'int*' to 'int'
Sort.cpp:25: error: initializing argument 1 of 'bool Sort::sortedIsEmpty(int)'Sort.cpp:29: error: invalid conversion from 'int*' to 'int'
Sort.cpp:29: error: initializing argument 1 of 'int Sort::sortedGetLength(int)'
Sort.cpp:39: error: invalid conversion from 'int*' to 'int'
Sort.cpp:39: error: initializing argument 1 of 'int Sort::sortedGetLength(int)'
Sort.cpp: At global scope:
Sort.cpp:49: error: prototype for 'bool Sort::sortedIsEmpty(int*)' does not match any in class 'Sort'
Sort.h:20: error: candidate is: bool Sort::sortedIsEmpty(int)
Sort.cpp:63: error: prototype for 'int Sort::sortedGetLength(int*)' does not match any in class 'Sort'
Sort.h:21: error: candidate is: int Sort::sortedGetLength(int)

I cant figure out to to fix these errors. Also one last question. In
Sort::sortedIsEmpty is that a good way to check for an empty array or is there an easier way I dont know about. Thanks in advance.

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by John A
0

>What I cant figure out is how do I first make a call in main to go into my Sort constructor.
Are you talking of something like this?

Sort x(firstList, secondList);

As for your errors, they're because when you pass an array like this to a function:

Sort::Sort(int list1[], int list2[]){

Then you have to update your constructor, too:

Sort( int[], int[] );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.