You can use Enumerable.Any:

bool isEmpty = !list.Any();
if(isEmpty)
{
    // ...
}  

If the list could be null you could use:

bool isNullOrEmpty = list?.Any() != true;
Answer from Tim Schmelter on Stack Overflow
🌐
Bubble
forum.bubble.io › questions
Determining if List is Empty - Questions - Bubble Forum
February 6, 2019 - What’s the best (fastest) way to determine if a list is empty - checking if “count = 0” or if “:first item is empty”? Is there another way? I initially thought the list itself could be checked if empty since the “is empty” operator is available, but apparently that can’t be done.
🌐
Cplusplus
cplusplus.com › reference › list › list › empty
std::list::empty
Returns whether the list container is empty (i.e. whether its size is 0). This function does not modify the container in any way.
Top answer
1 of 2
1

First of all you don't need double pointer. Initialization with NULL is important here. (Denotes the empty list).

SortedList *list = NULL;

This has the benefit that now if you want to make changes to it pass it's address.

func(&list);

And checking the empty list would be

   void func(SortedList **list){
      if( *list == NULL )
        /* empty */
   }

This is usually the way lists are implemented.


In your case you simply allocated to a local variable and instead of returning the memory address you have overwritten the pointer's value with NULL - there is memory leak in the code.

With your code it will be something like. Yes all that the initialization does is assigning it to NULL. This is one easy way out towards checking the NULL. At the very beginning making it NULL basically denotes that list is empty.(which is the case generally).

2 of 2
0

list is a pointer to a pointer. The actual list is in the value it points to, so you need to dereference it.

An empty list is just a null pointer, so you don't need to allocate anything in init().

void init(SortedList** list)
{
    *list=NULL;
    printf("%p\n", *list);
}
void isEmpty(SortedList** list)
{
    printf("%p\n", *list);
    if(*list == NULL) printf("List is empty\n");]
}

And in the main function, you don't need a double pointer, you use the & (address-of) operator to get the address of a pointer variable.

int main()  
{
    SortedList *list;
    init(&list);
    printf("Initialization with succes\n");
    isEmpty(&list);

    return 0;
}

You only really need double pointers for functions that modify the list. So you could use an ordinary pointer for isEmpty:

void isEmpty(SortedList* list)
{
    printf("%p\n", list);
    if(list == NULL) printf("List is empty\n");]
}

and then call it as:

isEmpty(list);

But it's probably simplest to be consistent across all your functions.

🌐
DaniWeb
daniweb.com › programming › software-development › threads › 156691 › linked-lists-find-length-and-check-for-empty-list
Linked Lists: Find length and check for empty list - DaniWeb
Your insertBack uses a local first that is never passed in; pass both first and last by reference so you can handle the empty-list case. In deleteFront, do not test first->info == 1; instead, check first != NULL before dereferencing, unlink the head, delete it, and set last = NULL if the list becomes empty.
🌐
SourceBae
sourcebae.com › home › how do i check if a list is empty?
How do I check if a list is empty? - SourceBae
August 21, 2025 - It may seem like a simple task, but overlooking an empty list can lead to errors and unexpected behavior in your code. In this blog post, we will delve into the importance of checking if a list is empty, explore different methods to accomplish this task, and provide examples and code snippets ...
🌐
TutorialsPoint
tutorialspoint.com › chash-program-to-check-whether-a-list-is-empty-or-not
C# program to check whether a list is empty or not
Now to check whether a list is empty or not, use the Count property. if (subjects.Count == 0) Console.WriteLine("List is empty!"); Now let us see the complete code.
Find elsewhere
🌐
Quora
quora.com › What-is-the-best-way-to-check-if-a-linked-list-is-empty-or-not-in-C
What is the best way to check if a linked list is empty or not in C++? - Quora
Usually, you will use the Standard Template Library, where a linked list is implemented as std::list. In this case, you can just use the empty() method that returns true if the list is empty and false if it is not empt...
🌐
Javatpoint
javatpoint.com › post › cpp-list-empty-function
C++ List empty() Function - Javatpoint
C++ List empty() function checks whether the list is empty or not. It returns true, if the list is empty otherwise false. It does not modify the content of the list · It does not contain any parameter
🌐
Cppreference
en.cppreference.com › w › cpp › container › list › empty
std::list<T,Allocator>::empty
Checks if the container has no elements. ... #include <list> #include <iostream> int main() { std::list<int> numbers; std::cout << std::boolalpha; std::cout << "Initially, numbers.empty(): " << numbers.empty() << '\n'; numbers.push_back(42); numbers.push_back(13317); std::cout << "After adding elements, numbers.empty(): " << numbers.empty() << '\n'; }
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 744707 › how-can-i-find-if-particular-index-in-a-list-is-em
How can I find if particular index in a list is Empty ? - Microsoft Q&A
Add comment · Answer accepted by question author · P a u l • · 10,766 Reputation points · 2022-02-21T19:08:12.127+00:00 · If you want to check if the zero'th element of every list is an empty string you could use .All(): bool isEmpty = ...
🌐
Meziantou's blog
meziantou.net › checking-if-a-collection-is-empty-in-csharp.htm
Checking if a collection is empty in C# - Meziantou's blog
January 29, 2024 - In this post, I describe how to check if a collection is empty in C#, whatever the type of the collection
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › list-empty-function-in-c-stl
list empty() function in C++ STL - GeeksforGeeks
May 29, 2023 - The list::empty() is a built-in function in C++ STL that is used to check whether a particular list container is empty or not. This function does not modify the list, it simply checks whether a list is empty or not, i.e.
🌐
Narkive
comp.lang.lisp.narkive.com › Mz5P3P6Z › how-to-check-if-a-list-is-empty-or-nil
how to check if a list is empty or nil?
Post by ssecorp (not (= lst nil)) (/= lst nil) empty?, list?, nil? does not work either. do I really have to use (= 0 (length lst)) seems inefficient if the lists can be big. lst. Or list if you realize you are not doing scheme. kt huh? I think Kenny's point is that you can use the name "list" rather than "lst", and this will not conflict with the function (named "list") because, unlike scheme, CL has a separate namespace for functions.
🌐
Medium
medium.com › @martinstm › performance-wars-checking-empty-lists-c-47be0557161e
Performance Wars — Checking Empty Lists — C# | by Tiago Martins | Medium
October 30, 2021 - The worst result was for FirstOrDefault() method from LINQ. Again this method cast the list to IList and checks if the Count is greater than 0, if so returns the first element. If can’t convert to IList calls the MoveNext and return that element. In case of the list be empty, will return null (source code).
🌐
IncludeHelp
includehelp.com › stl › std-list-empty-function.aspx
std::list::empty() function in C++ STL
empty() is the function of list class, it is used to check whether a list container is empty or not, it returns true (integer value: 1) if list container is empty i.e.
🌐
GitHub
gist.github.com › madcoda9000 › 076de785b7420693caf8d0c4ea079eea
[check if list is empty] #c# · GitHub
[check if list is empty] #c#. GitHub Gist: instantly share code, notes, and snippets.