diff --git a/1.cpp b/1.cpp index 190c209..a979128 100644 --- a/1.cpp +++ b/1.cpp @@ -6,21 +6,24 @@ class container { int size; public: float* p; - container(int s) :size(s){} - const int& getsize() { return size;} - + container(int s) :size(s) {} + const int& getsize() { return size; } + const int& getsize() const { return size; } }; class vector :public container { int call_num; public: - explicit vector(int l) :len(l),size(1 * 100){ + explicit vector(int l) :len(l), container(1 * 100) { + p = new float(); + } + vector(const container& m) :len(10), container(m.getsize()) { p = new float(); } int len; - int& getlen() const { - call_num ++; + int& getlen() { + call_num++; return len; } ~vector() = default; @@ -32,9 +35,10 @@ int main() { vector v1 = c1; container& r1 = v1; container c2 = 100; - c2.getsize() = 20; + c2.getsize(); cout << c2.getsize(); - vector v2 = 100; - v2.getlen = 40; + vector v2 = (vector)100; + v2.getlen() = 40; cout << v2.getlen(); -} \ No newline at end of file +} +//output after debug:10040 \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..30d0477 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,11 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count; - for (int i = 0; i <= arrLength; ++i) + int count=0; + for (int i = 0; i < arrLength; ++i) for (int j = 0; j <= sArr[i].size(); ++j) // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + if (sArr[i][j] == specificChar) count++; return count; } diff --git a/3.cpp b/3.cpp index c8732ef..583ee9c 100644 --- a/3.cpp +++ b/3.cpp @@ -1,9 +1,12 @@ -#include +#pragma warning(disable : 4996) + +#include #include +#include #define MAX_SIZE 200 int arr[MAX_SIZE]; -typedef struct alfa * alfaptr; +typedef struct alfa* alfaptr; struct alfa { long long x; @@ -15,8 +18,12 @@ void push(int x) alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; + node->next = NULL; if (!front) + { front = node; + rear = node; + } else { rear->next = node; rear = node; @@ -31,6 +38,7 @@ void pop() else { node = front->next; + free(front); front = node; } } @@ -39,21 +47,31 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) + { if (node->x == x) - printf("%d", counter); + { + counter++; + printf("%d\n", counter); + } else { - printf("ERROR2"); - break; + printf("ERROR4"); } node = node->next; + } } void rpop() {//pop last element - alfaptr node = front; - while (node) - node = node->next; - free(rear); - rear = node; + if(front!=rear) + { + alfaptr node = front; + free(rear); + while (node->next != rear) + node = node->next; + rear = node; + } + else { + printf("ERROR3"); + } } void set() @@ -66,15 +84,17 @@ void set() int size() { alfaptr node = front; - int count; - while (node) - count++;node = node->next; + int count=0; + while (node!=rear->next) + { + ++count; node = node->next; + } return count; } void show() { - if (!front) { + if (front) { for (int i = 0; i < MAX_SIZE; i++) printf("%d ", arr[i]); } @@ -88,7 +108,7 @@ int average() { alfaptr node = front; - int sum = 0, count; + int sum = 0, count=0; while (node) { sum += node->x; count++; diff --git a/4.cpp b/4.cpp index a9a32f2..e02c22e 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,5 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} +//no bug output 78.000000 \ No newline at end of file diff --git a/5.cpp b/5.cpp index e9a1737..7762af5 100644 --- a/5.cpp +++ b/5.cpp @@ -7,4 +7,9 @@ int main() printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} + +//no bug +//output +//50 +//2 \ No newline at end of file diff --git a/6.cpp b/6.cpp index bb721c3..472b802 100644 --- a/6.cpp +++ b/6.cpp @@ -9,3 +9,7 @@ int main() printf("%d\n", a); return 0; } +//no bug +//output +//513 +// diff --git a/7.cpp b/7.cpp index 7b065a0..0031ee5 100644 --- a/7.cpp +++ b/7.cpp @@ -7,4 +7,7 @@ int main() p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +//no bug +//output +//3 \ No newline at end of file diff --git a/8.cpp b/8.cpp index 76b870c..1028969 100644 --- a/8.cpp +++ b/8.cpp @@ -11,3 +11,7 @@ int main() { } +//no bug +//output +//Be WooW +