Intersection between Two Sorted List

This is a discussion on Intersection between Two Sorted List within the C Programming forums, part of the General Programming Boards category; Dear all, I need to seek help and am terribly stuck with. The question is : Given two sorted lists, ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Question Intersection between Two Sorted List

    Dear all,

    I need to seek help and am terribly stuck with.

    The question is :

    Given two sorted lists, L1 and L2, and write a procedure to compute L1 n L2 (intersection) using only the basic list operations.


    I need a full running program for this question.
    But i only managed to get some simple codings done, which i don't even know if i am right.

    My simple codes :

    stack nodes;
    while (L1_cur_node != NULL or L2_cur_node != NULL)
    if (L1_cur_node.data = = L2_cur_node.data) {
    nodes.push (L1_cur_node.data);
    L1_cur_node = L1_cur_node.next;
    L2_cur_node = L2_cur_node.next
    } else if (L1_cur_node.data < L2_cur_node.data) {
    L1_cur_node = L1_cur_node.next;
    } else {
    L2_cur_node = L2_cur_node.next;
    }
    }


    Can someone please help me with a full running program?

    Thank you.

    lilpig
    Last edited by lilpig; 04-11-2002 at 02:30 PM.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212

    Angry

    This is an ASSIGNMENT, I know this is an ASSIGNMENT. We will help if you have something but we won't write your damn assignment. Didn't you read the conditions when you signed up.
    Last edited by kwigibo; 04-12-2002 at 01:26 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,831
    > while (L1_cur_node != NULL or L2_cur_node != NULL)
    Should be
    while (L1_cur_node != NULL and L2_cur_node != NULL)

    Algorithm seems OK, try turning it into actual C code - it's almost there as it is.


    > using only the basic list operations
    Start with these, and make sure they work, before trying the main problem.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    2

    Wink

    Thanks for reading.
    I have got this question done and has got it running.


    Thanks Salem!
    I have got it running and done this afternoon!
    Thanks for the correction. It was the intersection which i made a blunder.
    Last edited by lilpig; 04-12-2002 at 08:55 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a sorted list
    By S15_88 in forum C Programming
    Replies: 3
    Last Post: 03-20-2008, 02:14 AM
  2. circular doubly linked list help
    By gunnerz in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2007, 09:38 PM
  3. Inserting new nodes in a sorted double linked list
    By carrja99 in forum C++ Programming
    Replies: 2
    Last Post: 03-07-2003, 08:34 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21