Thread: Help with Reverse Array

  1. #1
    Registered User
    Join Date
    Apr 2007

    Question Help with Reverse Array

    I've tried and tried to solve this problem, but I cannot do it. Here is the question:

    Write the definition of a function, isReverse , whose first two parameters are arrays of integers of equal size, and whose third parameter is an integer indicating the size of each array. The function returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.)

    Here is what I've tried:

    bool isReverse (int arr1 [], int arr2 [], int n) {
    	for (int k = 0; k <  n; k++)
    	if (arr1 [k] == arr2 [n - 1 - k])
    	return true;
    		return false;
    My professor tells me it returns true for the first time, but what about the other times
    This is the message the lab gives me:

    It seems that your function fails to check the ends of the
    arrays. Please revise your code.

    I don't know what else to try. I would appreciate somebody's help, please!

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    You don't want to return after checking the first element. You can return false if they don't match because if the first two don't match then the arrays aren't reverses of each other. But just because the first two match doesn't mean that the rest match. You can't return true yet. You have to continue in your loop. You can only return true after you have run the full loop.
    Don't quote me on that... ...seriously

  3. #3
    Registered User
    Join Date
    Apr 2007
    Thank you so much, I got it right now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  2. Reverse Print Vector Array help
    By guda in forum C++ Programming
    Replies: 2
    Last Post: 11-11-2002, 06:47 PM
  3. how do I reverse order of my array
    By jgonzales in forum C++ Programming
    Replies: 6
    Last Post: 09-25-2002, 03:48 PM
  4. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM
  5. read into array and spit out in reverse order
    By steven in forum C Programming
    Replies: 4
    Last Post: 09-07-2001, 02:27 PM