Skip to main content
deleted 93 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. I would suggest that you rename size to allocatedSize to avoid confusion between size and length.
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. I would suggest that you rename size to allocatedSize to avoid confusion between size and length.
deleted 93 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. In your constructor you set length to zero instead of the initial size. length = size;
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. In your constructor you set length to zero instead of the initial size. length = size;
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
deleted 10 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that basically does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. In your constructor you set length to zero instead of the initial size. length = size;
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that basically does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. In your constructor you set length to zero instead of the initial size. length = size;
  1. Consider using size_t instead of int. The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to problems, particularly as 64-bit architectures become more prevalent.

  2. It is generally bad practice to repeat code that does the same thing. Consider changing copyToNewSize to something like this:

void copyToNewSize(size_t newSize) {
    int* temp = new int[newSize];
    size_t copySize = std::min(size, newSize);
    for (size_t i = 0; i < copySize; i++) {
       temp[i] = arr[i];
    }
    delete[] arr;
    size = newSize;
    arr = temp;
}
  1. In your constructor you set length to zero instead of the initial size. length = size;
added 92 characters in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
deleted 1 character in body
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading
Source Link
jdt
  • 2.5k
  • 6
  • 22
Loading