comp2list.txt

来自「It is an ebook about data structures,mai」· 文本 代码 · 共 38 行

TXT
38
字号
How to compare two linked lists? Write a C program to compare two linked lists. 

Discuss it!          

Here is a simple C program to accomplish the same. 


int compare_linked_lists(struct node *q, struct node *r) 
{ 
    static int flag; 
     
    if((q==NULL ) && (r==NULL)) 
    { 
         flag=1; 
    } 
    else 
    { 
        if(q==NULL || r==NULL) 
        { 
            flag=0; 
        } 
        if(q->data!=r->data) 
        { 
            flag=0; 
        } 
        else 
        { 
           compare_linked_lists(q->link,r->link); 
        } 
    } 
    return(flag); 
} 



Another way is to do it on similar lines as strcmp() compares two strings, character by character (here each node is like a character). 
 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?