+
Manav
Which is the best book for dsa
[BLĀNK]
[BLĀNK]
Just practice any algorithm that you see dude
Anonymous
Ok
Anonymous
Hello guys.
Considering the follow simple snippet:
node** pointer = (node**)malloc(sizeof(node*));
// Do stuff with pointer
free(pointer);
I was wondering why valgrind calls "invalid free" on free(pointer)
Prakhar
Given a weighted undirected graph, you have to find the shortest distance between source and destination given you can remove k edges from the path.
Prakhar
updull
Thanks admin❤️
DEV 7
#include<iostream>
#include<string>
using namespace std;
int main(){
string st;
int count=0;
cout<<"enter the name"<<endl;
cin>>st;
for (int i = 1; i <=st.length(); i++)
{
if ((st.at(i)='a')||(st.at(i)='e')||(st.at(i)='i')||(st.at(i)='o')||(st.at(i)='u'))
{
count=count++;
}
}
cout<<"no of vowels"<<count;
return 0;
}
Anonymous
DEV 7
program to calculate all vowels in string, but it did not work
Anonymous
DEV 7
Anonymous
DEV 7
ꍏꈤꀸ
Anonymous
Anonymous
Anonymous
Anonymous
Anonymous
Exception handling can be expensive. So it is better to check your indexes before accessing the index rather than using at and let it throw an exception.
You would use at only in those functions where in your preconditions it is a requirement that the index passed in to the function be valid. You would declare such a function noexcept and use at. In such cases when the user passes in an invalid index, it is a precondition violation and thus all bets are off. So an exception out of this noexcept function would terminate the program which is acceptable Behavior.
Anonymous
Anonymous
Anonymous
Stanislav
https://en.cppreference.com/w/cpp/string/byte/strtoul
Six
Hey i'm trying to understand why this function has two different outputs when the condition is met.
add(); makes a random number 1-3.
result(); is outputing "Works" when random number is 3 and "No work" when 1 or 2.
I have put the result(); function inside of add(); where it outputs correctly when 3, 2 and 1. But the result(); inside of my main(); function always "no work" even when its 3. Attached a pastebin of the code.
https://pastebin.com/Qmvm1kHn
hb
Six
Anonymous
DEV 7
best resource for template and stl in c++
Anonymous
best resource for template and stl in c++
C++ Templates: The Complete Guide by Nicolai Josuttis et al. (2nd edition covers upto C++17)
for C++20 changes (most important imo is Concepts) look at Rainer Grimm's blog.
Anonymous
as for the library, all good C++ books cover them. look at cppreference for a complete reference.
Anonymous
Deleted Account
makefile how to read .depend file?
Anonymous
🤷 look at the code
Is there any way to keep an eye on an allocated block of memory?
Anshul
accessing elements in a deque by offsetting a pointer to another element causes undefined behavior.
Anshul
what is the meaning of this sentence
Anshul
How deque is implemented internally in stl if it doesn't have it's elements in contiguous memory! the cplusplus refrence site says they're implemented using dynamic arrays but then why the memory is no contiguous
Anshul
"Therefore, they provide a functionality similar to vectors, but with efficient insertion and deletion of elements also at the beginning of the sequence, and not only at its end. But, unlike vectors, deques are not guaranteed to store all its elements in contiguous storage locations: accessing elements in a deque by offsetting a pointer to another element causes undefined behavior."
Anonymous
Anshul
Anonymous
okay! so then how the operator[ ] is overloaded
Internally deque maintains a pointer to its internal vectors. So when you ask for an element at a specific index, it knows which vector it will be in. It then fetches the element from that vector. Btw this is just one of the possible ways of implementing a deque. There are others too.
Anonymous
And when I use the term vector, I actually mean a contiguous storage. It could be a dynamic array or a STL vector
Anshul
from where i can learn how deques are implemented internally??
Anshul
i'm not able to understand anything by looking at that code.
Anshul
#ifndef _GLIBCXX_DEQUE
#define _GLIBCXX_DEQUE 1
#pragma GCC system_header
#include <bits/stl_algobase.h>
#include <bits/allocator.h>
#include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
#include <bits/stl_deque.h>
#include <bits/range_access.h>
#include <bits/deque.tcc>
#ifdef _GLIBCXX_DEBUG
# include <debug/deque>
#endif
#ifdef _GLIBCXX_PROFILE
# include <profile/deque>
#endif
#endif /* _GLIBCXX_DEQUE */
Anshul
is there no simple understandable implementation available anywhere? actually i couldn't find anything in the DSA course i'm enrolled in
Anshul
You're right!
Anonymous
Kishore
What are the topics should I need to cover in Dsa part? Could anyone tell me?
Anonymous
Anonymous
this has some explanations in the comments too
https://github.com/electronicarts/EASTL/blob/master/include/EASTL/deque.h
Anonymous
Hanz
#ASK
Simple question, what does for (;;) means?
Is that different from while (1)?
Ludovic 'Archivist'
Hanz
Thanks for your answer 🙏
bunny
hello guys i need small help.
Like i want to set a range of a variable so that after incrementing its value from the last it should jump back to the first value.
bunny
just like 12 for month
bunny
if we increment from 12 it should jump back again to 1
bunny
/report
Anonymous️
Sry
バレンタインがいない柴(食用不可)
Hanz
that's it!
bunny
Anonymous
Anonymous
// member initialization
#include <iostream>
using namespace std;
class Circle {
double radius;
public:
Circle(double r) : radius(r) { }
double area() {return radius*radius*3.14159265;}
};
class Cylinder {
Circle base;
double height;
public:
Cylinder(double r, double h) : base (r), height(h) {}
double volume() {return base.area() * height;}
};
int main () {
Cylinder foo (10,20);
cout << "foo's volume: " << foo.volume() << '\n';
return 0;
}