how to count the no. in an array or list?
count
Collapse
X
-
Tags: None
-
I cant get you.Originally posted by MOHIT0RMAYANKhow to count the no. in an array or list?
Can you explain a bit more clearly
Raghuram -
Are you asking how you would get the length of either of those data structures? Iterate through each node in whatever structure, adding to a counter. At the end, you have the length. In an array, it is just iteration through elements, and in a list, it is iteration through the nodes.Comment
-
Any easier way to get the length of an array would be to do
int arr[100];
int size = sizeof(arr)/sizeof(int);
you can do this for any data type
hell, if you're using stl c++ data types like deque, list, or any others, it is simply
list foo;
foo.size();
or stl string type use length
cppreference.co mComment
-
std::string::le ngth() is deprecated. You are supposed to use std::string::si ze() like the other STL containers.Originally posted by mschenkelbergor stl string type use lengthComment
Comment