C Programming Tutorial

 
 
 
 
#include <stdio.h>
#include <conio.h>
#include <alloc.h>

struct node
{
    int data ;
    struct node *link ;
} ;

void append ( struct node **, int ) ;
int compare ( struct node *, struct node * ) ;

void main( )
{
    struct node *first, *second ;
    first = second = NULL ;  /* empty linked lists */

    append ( &first, 1 ) ;
    append ( &first, 2 ) ;
    append ( &first, 3 ) ;

    append ( &second, 1 ) ;
    append ( &second, 2 ) ;
    append ( &second, 3 ) ;

    clrscr( ) ;
    if ( compare ( first, second ) )
        printf ( \"Both linked lists are EQUAL\" ) ;
    else
        printf ( \"Linked lists are DIFFERENT\" ) ;
}

/* adds a node at the end of a linked list */
void append ( struct node **q, int num )
{
    struct node *temp ;
    temp = *q ;

    if ( *q == NULL )  /* if the list is empty, create first node */
    {
        *q = malloc ( sizeof ( struct node ) ) ;
        temp = *q ;
    }
    else
    {
        /* go to last node */
        while ( temp -> link != NULL )
            temp = temp -> link ;

        /* add node at the end */
        temp -> link = malloc ( sizeof ( struct node ) ) ;
        temp = temp -> link ;
    }

    /* assign data to the last node */
    temp -> data = num ;
    temp -> link = NULL ;
}

/* compares 2 linked lists and returns 1 if linked lists are equal and 0 if
    unequal */
int compare ( 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 ( q -> link, r -> link ) ;
    }
    return ( flag ) ;
}

    Related Post:
  1. Implement a multi-access threaded queue with multiple threads inserting and multiple threads extracting from the queue

  2. delete and insert anode at end in doubly link list.

  3. Program that accepts characters in lower case, stores them in an array and prints them in the upper-case and vice - versa

  4. Example 5 of using function

  5. Program to compute sum of those integers that are evenly divisible by 5 Use if-else statement

  6. Program to determine entered number is prime or not

  7. PROGRAM FOR HISTOGRAM FOR INDIVIDUAL CELL OF HISTOGRAM THERE ARE SEPARATE LOCK

  8. Program to multiply two polynomials maintained as linked lists

  9. Program to read a file name, serach it in the whole Hard Drive and delete it if found

  10. Program that reads the encoded alphabetic text from a file and produces decoded file by replacing each character with the character that occurs five

  11. Write a function to perform string operation i.e. split, join, length, substring using pointer without using any string function

  12. Program to display * in triangle

  13. Example of passing structure to function

  14. Program that performs add, edit, delete, display and search data from file

  15. Program that implements breadth first search algorithm

  16. Program to read a series of words from a terminal using scanf function

  17. Overcome forward dependency using block scheduling copy arr[i+1] to arr[i]

  18. PROGRAM TO FIND AREA & CIRCUMFERENCE OF A CIRCLE

  19. PROGRAM TO FIND ANSWER OF THE FOLLOWING SERIES. INPUT STEPS FROM KEYBORD. SUM=X-X3/3!+X5/5!-X7/7!+...(TAKE VALUE OF X ALSO).

  20. Program to print string in different pattern

 
 
Didn't find what you were looking for? Find more on Program to compare two linked lists using recursion