Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Title #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ class container {
public:
float* p;
container(int s) :size(s){}
const int& getsize() { return size;}
int& getsize() { 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();
}
int len;
int& getlen() const {
int& getlen() {
call_num ++;
return len;
}
Expand All @@ -29,12 +29,12 @@ class vector :public container {
int main() {

container c1(100);
vector v1 = c1;
vector v1 (100);
container& r1 = v1;
container c2 = 100;
c2.getsize() = 20;
cout << c2.getsize();
vector v2 = 100;
v2.getlen = 40;
vector v2(100);
v2.len = 40;
cout << v2.getlen();
}
8 changes: 4 additions & 4 deletions 2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
for (int j = 0; j <= sArr[i].size(); ++j)
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;
}
Expand Down
45 changes: 40 additions & 5 deletions 3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void push(int x)
alfaptr node;
node = (alfaptr)malloc(sizeof(struct alfa));
node->x = x;
node->next = NULL;

if (!front)
front = node;
else {
Expand All @@ -31,11 +33,24 @@ void pop()
else
{
node = front->next;
free(front);
front = node;

if (!front)
{
rear = NULL;
}

}
}
void search(int x)
{
if (!front)
{
printf("ERROR1");
return;
}

alfaptr node = front;
int counter = 0;
while (node)
Expand All @@ -46,14 +61,31 @@ void search(int x)
break;
}
node = node->next;
counter++;
}

void rpop() {//pop last element
alfaptr node = front;
alfaptr prev = NULL;

while (node)
{
prev = node;
node = node->next;
free(rear);
rear = node;
}

if (node == front)
{
free(front);
front = NULL;
rear = NULL;
} else if (prev)
{
free(prev->next);
prev->next = NULL;
rear = prev;
}

}

void set()
Expand All @@ -66,9 +98,12 @@ void set()
int size()
{
alfaptr node = front;
int count;
int count = 0;
while (node)
{
count++;node = node->next;
}

return count;
}

Expand All @@ -88,7 +123,7 @@ int average()
{

alfaptr node = front;
int sum = 0, count;
int sum = 0, count = 0;
while (node) {
sum += node->x;
count++;
Expand All @@ -97,7 +132,7 @@ int average()
return sum / count;
}

void main()
int main()
{
int cmd;
long long int x;
Expand Down
5 changes: 4 additions & 1 deletion 4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ int main()
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f", *ptr2 - *ptr1);

return 0;
}
}

// 78.000000
5 changes: 4 additions & 1 deletion 5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ int main()
printf("%d\n", (*ptr2 - *ptr1));
printf("%c", (char)(*ptr2 - *ptr1));
return 0;
}
}

// 50
// 2
2 changes: 2 additions & 0 deletions 6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ int main()
printf("%d\n", a);
return 0;
}

// 513
4 changes: 3 additions & 1 deletion 7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ int main()
p += 2;
printf("%d", *p);
return 0;
}
}

// 3
5 changes: 3 additions & 2 deletions 8.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include<stdio.h>
#include<stdio.h>
const char * f(const char **p) {
auto q = (p + sizeof(char))[1];
return q;
Expand All @@ -9,5 +9,6 @@ int main() {
printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1));



}

// Be WooW