![linked list stack get mentain minimum number linked list stack get mentain minimum number](http://flameinstitute.com/wp-content/uploads/2015/11/420203_4336422924216_1265322456_n-400x600.jpg)
- Linked list stack get mentain minimum number update#
- Linked list stack get mentain minimum number 32 bit#
If you actually need the entire size of the list including allocated elements for all other char* pointers for example, you simply:ġ)Traverse the list and look into each nodeĢ)For each node you check if the elements of each node point to any other allocation (for This will need to be accounted for.įor instance, one of those char* elements within the node could malloc some more space and use up some memory. This will give you the size of the actual linked list but becareful as the linked list node has pointer elements which in and of themselves can allocate memory as well. Size = getCountOfList * sizeof(mydatatype) Then you take that count and multiply by size: Node* temp = head //assign a temp node to the head of the list So to get the total size of the linked list you traverse the list and get the count of nodes: Total Size Of Linked List = SizeOf(One Node) * Count Of Nodes Once you allocate memory for a node (using malloc) you should be able to do sizeof(yourDataType).
Linked list stack get mentain minimum number 32 bit#
Which is the difference? sizeof(Data_Struct) = 16īecause the Data_Struct type contains 4 pointers, three for pointers to char and one for the next element in the list sizeof(Name) = sizeof(Task) = sizeof(Pos) = 4īecause these variables are of type pointer to char, so they are pointer, no concrete value, and it's usually 4 bytes (I'm assuming a 32 bit architecture) strlen(Name) = length in chars of the stringīecause the function works exactly to calculate the length of a string.
![linked list stack get mentain minimum number linked list stack get mentain minimum number](https://res.cloudinary.com/practicaldev/image/fetch/s--nlPnqN1I--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/iucqi0ezy56ftc5pyi57.png)
Mind that since data inside your list element if of type char* the effective size of the Data_Struct is just 4 pointers, that's why you need to use a support function like strlen, otherwise you can't get real dimension of the strings. In your case you can keep the same approach used for calculating the length but instead that adding 1 for every element you should add the total length of strings: size += strlen(Name)+strlen(Task)+strlen(Pos)
Linked list stack get mentain minimum number update#
You could store size somewhere and update with list insertions and deletes to avoid any overhead and being able to calculate it in a constant time O(1).ĭidn't notice you wanted size of the whole data included into the list. Mind that complexity of this operation is linear with the size of the list, so it's O(n) and it's quite inefficient. You usually go through the list until you reach the tail item while counting in the meanwhile, code should be something like that: int listLength(struct Data_Struct* item)