This C Program checks whether 2 lists are the same. The lists are said to be same if they contain same elements at same position. Here is source code of the C Program to check whether 2 lists are the same. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
$ cc checklinklist.c $ ./a.out Enter data into first list Enter number: 12 Do you wish to continue [1/0]: 1 Enter number: 3 Do you wish to continue [1/0]: 1 Enter number: 28 Do you wish to continue [1/0]: 1 Enter number: 9 Do you wish to continue [1/0]: 0 Enter data into second list Enter number: 12 Do you wish to continue [1/0]: 1 Enter number: 3 Do you wish to continue [1/0]: 1 Enter number: 28 Do you wish to continue [1/0]: 1 Enter number: 9 Do you wish to continue [1/0]: 0 The 2 list are equal. Sanfoundry Global Education & Learning Series – 1000 C Programs. Here’s the list of Best Books in C Programming, Data-Structures and Algorithms Next Steps:
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn. Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses. How to compare two linked list in C?We'll compare these linked lists using the check_equal() function. The check_equal() function traverses the linked lists until at least one of them reaches to NULL (end). If the value fields of two linked list are not equal at any point, the function returns 0 (not equal).
How do you compare data in two linked lists?Check if Linked-Lists are identical using linear traversal:. Traverse both the linked lists simultaneously. If the data of the current node for one linked list is not equal to the node of the other one, then return false.. Return true, as both the linked lists are identical.. How to compare two items in a list C#?Equals(Object) Method which is inherited from the Object class is used to check if a specified List<T> object is equal to another List<T> object or not. Syntax: public virtual bool Equals (object obj);
Can we compare two linked list?Given two strings, represented as linked lists (every character is a node in a linked list). Write a function compare() that works similar to strcmp(), i.e., it returns 0 if both strings are the same, 1 if the first linked list is lexicographically greater, and -1 if the second string is lexicographically greater.
|