Anonymous
For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./a.out... (gdb) r Starting program: /data/data/com.termux/files/home/a.out At the beginning there are 0 objects constructed. And there are 0 elements in the linkedlist container. Inserting 20 objects with insert_increasing member function *********************************************************** Inserting Square Orange Area = 25.00 Per. = 20.00 Side = 5.00 Inserting Square Yellow Area = 1.00 Per. = 4.00 Side = 1.00 Program received signal SIGSEGV, Segmentation fault. 0x000000555555890c in Node::setLink (this=0x0, p=@0x7ffffff148: 0x7ffffff170) at codebeautify.cpp:316 316 void Node::setLink(const NodePtr& p) { link = p; } (gdb) quit
Anonymous
Also, error's in tail_insert for whoever can try to help, because segmentation fault shows up without the use of insert_increasing too
Mar!o
why do you pass pointers by reference? If NodePtr is Node* you are doing: const NodePtr*& which is not needed. Pointers are cheap to copy they are 32-bits on 86 and 64 bits on 86_64. Passing them by reference only makes sence with smart pointers or with a mutable reference if you want to return a pointer and in C++ you should use a ref 2 ptr instead of a double pointer **
olli
Also, error's in tail_insert for whoever can try to help, because segmentation fault shows up without the use of insert_increasing too
In your tail_insert you create a local node and take its address. You should not take address of local variables since they are destroyed once the function returns. void LinkedList::tail_insert(const ShapePtr& p){ Node newnode = Node(p); newnode.setLink(nullptr); NodePtr lst = head; if(head == nullptr){ head = &newnode; ^^^^^^^^ So once this functions returns head is not NULL but accessing it results in UB.
olli
yes that is indeed correct, maybe I can use new to create an object?
Yes, you need to dynamically allocate the node, e.g. using new
Anonymous
u0_a362@localhost:~$ g++ -g codebeautify.cpp u0_a362@localhost:~$ ./a.out At the beginning there are 0 objects constructed. And there are 0 elements in the linkedlist container. Inserting 20 objects with insert_increasing member function *********************************************************** Inserting Triangle Red Area = 7.50 Per. = 13.83 Base = 3.00 Height = 5.00 Inserting Square Black Area = 1.00 Per. = 4.00 Side = 1.00 Segmentation fault u0_a362@localhost:~$ gdb a.out GNU gdb (GDB) 9.2 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "aarch64-linux-android". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from a.out... (gdb) r Starting program: /data/data/com.termux/files/home/a.out At the beginning there are 0 objects constructed. And there are 0 elements in the linkedlist container. Inserting 20 objects with insert_increasing member function *********************************************************** Inserting Triangle Red Area = 7.50 Per. = 13.83 Base = 3.00 Height = 5.00 Inserting Square Black Area = 1.00 Per. = 4.00 Side = 1.00 Program received signal SIGSEGV, Segmentation fault. 0x000000555555890c in Node::setLink (this=0x0, p=@0x7ffffff1d8: 0x7fbdc2c020) at codebeautify.cpp:316 316 void Node::setLink(const NodePtr& p) { link = p; } (gdb)
Anonymous
void LinkedList::tail_insert(const ShapePtr& p){ NodePtr newnode = new Node(); newnode->setData(p); NodePtr lst = head; if(head == nullptr){ head = newnode; } else { while(lst != nullptr){ lst = lst->getLink(); } lst->setLink(newnode); } }
Anonymous
damn you're good
Anonymous
thank you very much
ברני
Hey, can someone give me a hint how I merge 2 arrays in the third but the third needs to organize the numbers from small to big?..
ברני
I need help with the right order on the third array..
ברני
merge then sort
After the merge I do the logic calculation for the smallest to the biggest in the third?
Alex
use STL algorithm. just call sort
ברני
use STL algorithm. just call sort
I'll send the task one sec
ברני
Question 3 - to run Write a function that receives two sorted arrays [arrays 1 and 2] and their size, and another array [array 3] that is not initialized and sized As a sum of 2 + 1 array sizes. The function will insert into array 3 the values ​​from arrays 1 and 2 in a sorted manner. The insertion of the values ​​into array 3 must be performed in one pass on each of arrays 1 and 2 (a solution that does not meet this requirement is not Will receive a score. For example: the function will get: 6 size, 1,3,5,9,20,257: 1 array 8 Size, 3,4,7,56,82,103,863,999: 2 arrays Array 3: The array contains 14 organs whose value is garbage After running the function: .1,3,3,4,5,7,9,20,56,82,103,257,863,999: 3 Array Exercise notes: There is no need to check that the arrays are sorted. Write a main that tests the function.
ברני
Im not asking for answers just hints if can it will help me better then answers 🙏
ברני
traverse two arrays from 0 to len, and insert min from both values on each step
Yes, but my logical struggle is how Im doing the 3th to take the numbers from the lowest to the highest instead of one after the other and the numbers won't be organized..
Alex
can`t understand your issue
Apk
he probably can't get the sorted array at the end
ברני
he probably can't get the sorted array at the end
I cant think how to make the third array not only to take the first and the second, also to make them 2 to be organized from the lowest to the highest..
ברני
if(a[i] >= '0' && '9' >= a[i] ) With this I can read the elements from left to right?
ברני
i don't understand this
int countDigits(char a[], int size) { int countDigits = 0; for(int i = 0; i < size; i++) { if(a[i] >= '0' && '9' >= a[i] ) { printf("%c", a[i]); countDigits++; } } return countDigits; } I used this to find a digit before
olli
ברני
I don't think this is required for the logic in any way
So what is it for? (don't want to do stuff that I don't understand.. I thought with this I counting the array from left to right)
NBC
Hello people. Has anyone worked with C project? I am looking for a tutor which can teach me modify a lines of a C code of my project. Inbox
NBC
Good question.
NBC
In fact it just is a little part of my final project in Java
NBC
Ok. Thanks
Anonymous
Gulshan
how to reduce time to execute this code?
Gulshan
Gulshan
I haven't shared the code, just asked what shall be done to reduce the time
Gulshan
Since I can't modify the int main() in hackkerrank
Anonymous
Bro I want learn c programming can u say
Gulshan
okay... srry
Gulshan
Bro I want learn c programming can u say
go check on yt... there are tons of tutorials
Gulshan
#mcve your picture clearly contains code
https://del.dog/reckovuxap.txt
Gulshan
https://del.dog/reckovuxap.txt
Please check and give me some tips so that I can reduce time for compiling this code, by only changing class add Elements
Gulshan
Where is that bro
Please atleast search... Eg. Freecodecamp,cherno,etc
Anonymous
Where I want to search in this group
Anonymous
Or YouTube or Google
Anonymous
Ha kk bro
Anonymous
Thank you
olli
https://del.dog/reckovuxap.txt
seems to be horribly designed test by hackerrank, try adding this before int main() int start_up() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); return 0; } static int r = start_up(); #define endl '\n';
Gulshan
But what do this snippet does ?
Gulshan
And can you please remove the warning, this will not happen again...
ברני
hey guys.. I still have troubles with the function of array number 3.. how can I calculate the lowest to the highest from the 2 arrays to the third?.. https://onlinegdb.com/HygcPuSWcP
ברני
i don't know what to do..and I didn't find the answer I was looking for in google..
Raru
I want to change this code with functions but i don’t know how , can you explain me if you know ?
olli
i don't know what to do..and I didn't find the answer I was looking for in google..
You have to store the indices a_i and b_i (technically speaking, you need c_i as well), while both are smaller than its array size, you select the smaller of a[a_i] and b[b_i] and write it into c. Increment the necessary indices. Once you reached the end of one array a or b copy the remaining elements of the other array into c
ברני
That's exactly what's happening here
Yes, I tried to understand what you sent but I got confused..
olli
Like: for (int i=0;i<size1;i++){ if (arr2[i] <arr1[i]) arr2[i] =arr1[I] } ?
No, you only have one index in your example. Looking at the picture you do not always compare the same index in both arrays. E.g. a couple steps in you compare a[0] against b[1], that will never happen in your snippet.
olli
I need to go cell by cell? A[0]>b[0] ?
that's what your first comparison should be, but you can't list all the comparisons as the number grows exponentially with the size of the array