Nikita
i need to do that with C
Anonymous
ok
Nikita
i need simply write a function which returns some element?
Sourabh
what's "in unsorted order"
leave it intact dont sort it either in ascending or in descending order.
R
/hello
R
/hello
Nikita
leave it intact dont sort it either in ascending or in descending order.
thnx but i still can't imagine what i should to do
R
Smoke some weed
Aquib
i need to do that with C
Do you have to implement the hash table as well
Anonymous
hellloooo
Anonymous
what is segfault ?
Anonymous
🤨
Mat
The language?
Francisco
But what, a compiler?
Mihail
You can't install c++. C++ is just a language
Mihail
You probably want a compiler
Mihail
I'd recommend Termux with clang or gcc
Aadarshhh
#include <stdio.h> #include <stdlib.h> #include <string.h> int* reverseArray(int a_count, int* a, int* result_count) { *result_count = a_count; int temp; for(int i = 0; i < a_count; i++) { temp = *(a + i); *(a+i) = *(a + a_count -i); //last elemnt is transfered to first *(a+ a_count -i) = temp; //first location is stored by last value } return a; } int main() { int arr_count =4; int* arr = malloc(arr_count * sizeof(int)); for (int i = 0; i < arr_count; i++) { scanf("%d", & *(arr + i)); } int res_count; int* res = reverseArray(arr_count, arr, &res_count); for (int i = 0; i < res_count; i++) { printf("%d", *(res + i)); if (i != res_count - 1) { printf(" "); } } printf("\n"); return 0; }
Aadarshhh
guys check my program it doesn't reverse the array
Aadarshhh
where I'm missing the point ?
Aadarshhh
In C , without using libraries
Aadarshhh
still doesn't works
Aadarshhh
still doesn't works
olli
done but
Can you post the updated code?
Aadarshhh
#include <stdio.h> #include <stdlib.h> #include <string.h> int* reverseArray(int a_count, int* a, int* result_count) { *result_count = a_count; int temp; for(int i = 1; i < a_count; i++) { temp = *(a + i); *(a+i) = *(a + a_count -i); //last elemnt is transfered to first *(a+ a_count - i) = temp; //first location is stored by last value } return a; } int main() { int arr_count =4; int* arr = malloc(arr_count * sizeof(int)); for (int i = 0; i < arr_count-1; i++) { scanf("%d", arr + i); } int res_count; int* res = reverseArray(arr_count, arr, &res_count); for (int i = 0; i < res_count; i++) { printf("%d", *(res + i)); if (i != res_count - 1) { printf(" "); } } printf("\n"); return 0; }
Francisco
Aadarshhh
https://pastebin.com/vVD2dTuk
olli
He said in C though
Aadarshhh
thank you so much :)
Aadarshhh
pointer is taking my mind. :(
Aadarshhh
I think I have to shift to STL for problem solving.. It's quite easier to use libraries tehere.
Sourabh
Cpp means is it a type of compiler right
CPP means C Plus Plus, it is a programming language... 😕
Anonymous
Hello
Sourabh
What is the use of having so many programming languages why cannot be a universal language which can cater all the needs like we have english language as an international language? (Need your thoughts on it, thank you!)
Aquib
You can create performant languages which are close to the machine
Aquib
Very similar to assembly
Aquib
But very tough to write
Aquib
Or you can write code very similar to human language
Aquib
But tough to optimise
Sourabh
But very tough to write
it should be simple as english
Aquib
it should be simple as english
Simple for us is tough for machine
MᏫᎻᎯᎷᎷᎬᎠ
Lolno
He 80% right
Sourabh
Simple for us is tough for machine
our language , should get properly interpret to machines
BinaryByter
He 80% right
10% maybe
MᏫᎻᎯᎷᎷᎬᎠ
10% maybe
Like java?!
MᏫᎻᎯᎷᎷᎬᎠ
Look at its performance
Aquib
Lolno
Humans need abstraction to understand stuff. More layer of abstraction means more translation. Intermediate code generation
BinaryByter
a good compiler should be able to convert any grammar into good code
BinaryByter
Like java?!
very bad example... 1) java performs almost as well as C++ in day to day 2) java is not similar to us
MᏫᎻᎯᎷᎷᎬᎠ
a good compiler should be able to convert any grammar into good code
If it has a an AI support xD I know there is an optimization
BinaryByter
Example
classes, namespaces, templates
Aquib
classes, namespaces, templates
Still low level abstractions
BinaryByter
If it has a an AI support xD I know there is an optimization
Not even then... Look at g++... it has a huge grammar to swallow
BinaryByter
Still low level abstractions
but not costly in perf
MᏫᎻᎯᎷᎷᎬᎠ
Well
BinaryByter
So java's performance is almost lile C++!!?
Yep... sometimes java is even faster when you dont compile your cpp for a native cpu
Aquib
So java's performance is almost lile C++!!?
No. An optimised c++ program will outperform optimised Java any day
MᏫᎻᎯᎷᎷᎬᎠ
Speaking of abstraction We have an example Templates Provide an abstraction of the type and keep the performance well
BinaryByter
Yep... sometimes java is even faster when you dont compile your cpp for a native cpu
Where java falls short is efficiency. Stuff like "lets not use the entire battery"
BinaryByter
No. An optimised c++ program will outperform optimised Java any day
Only if "optimized" means that you use the entire command set of your cpu
BinaryByter
Speaking of abstraction We have an example Templates Provide an abstraction of the type and keep the performance well
I wouldnt count them as abstraction, but thats my opinion. and yes, they cost nothing in terms of speed
BinaryByter
Optimised as in intelligently written.
No, it does not outperform java all day
BinaryByter
Java has become fast
Aquib
MᏫᎻᎯᎷᎷᎬᎠ
BinaryByter
Some java bytecodes are so specific that one single instruction says as much as 20 asm statemenrs