简体   繁体   English

C-双链表(isEmpty)

[英]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)); list1是这样的类型: 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"); 我添加了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) 您应该将参数传递给isEmpty(),例如isEmpty(struct list * l)或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. 它给出正确的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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