Thread: how to write a program that determines array from array

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    1

    Exclamation how to write a program that determines array from array

    How do I write a program that determines whether an array is part of another array?? ex.
    Code:
     array1[]={1,3,2,4,5,7,6}
    and the other array is
    Code:
     
    array2[]={3,2,4}
    I m sooo confused. ;'((((((

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Start by carefully defining your requirements. What does it mean for an array to be part of another array? For example, let's consider:
    Code:
    int array1[] = {1, 3, 2, 4, 5, 7, 6};
    int array2[] = {3, 2, 4};
    int array3[] = {1, 5, 7};
    int array4[] = {4, 6, 7};
    In the case of array2, its elements match a contiguous subsequence of array1. Is array2 part of array1? In the case of array3, its elements match a subsequence of array1. Is array3 part of array1? In the case of array4, each of its elements is equal to some element in array1, without regard for order. Is array4 part of array1?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 08-01-2013, 04:12 AM
  2. Replies: 1
    Last Post: 05-28-2011, 12:32 PM
  3. A program that determines odd numbers
    By metros in forum C Programming
    Replies: 2
    Last Post: 04-21-2010, 03:10 PM
  4. Replies: 8
    Last Post: 03-17-2010, 11:18 PM
  5. Replies: 8
    Last Post: 09-04-2008, 09:56 AM

Tags for this Thread