简体   繁体   中英

C - Doubly linked list (isEmpty)

I have doubly linked list and Ive made a function to check whether the list is empty or not.

Function code:

int isEmpty(list *l)
{
    if(l->head== NULL && l->tail== NULL)
        return 1;
    else
        return 0;
}

List

typedef struct list
{
    struct element *head;
    struct element *tail;
}list1;

and Im trying to use this function but there is nothing when i open console

case 11:
            printf("List is : %d\n", isEmpty(&list1));
            break;

list1 is a type so: printf("List is : %d\\n", isEmpty(&list1)); is meaningless,

Try:

list1 l1;
.
.
.
case 11:
    printf("List is : %d\n", isEmpty(&l1));
    break;

It was working but this messsage was disappearing after some milliseconds. I added system("pause"); and its working now.

You passing wrong parameter to the function. you should pass paramater to isEmpty() such as isEmpty(struct list* l) or isEmpty(list1* l)

     int isEmpty(struct list *l)          
     {
       if(l->head== NULL && l->tail== NULL)
           return 1;
       else
           return 0;
     }

call the function as

         isEmpty(list1)

it gives correct result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM