Rotation of elements of an array

This is a discussion on Rotation of elements of an array within the C++ Programming forums, part of the General Programming Boards category; I have written two rotation functions that operate on a character array of length equal to a perfect square. The ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    78

    Rotation of elements of an array

    I have written two rotation functions that operate on a character array of length equal to a perfect square.
    The first rotate n times each odd line to the right and n times each pair line to the left. The second rotates n times each odd column down and n times each pair column up, where n is the numer of current line or column.
    I would like to reduce everything to a single function, or rather, to a single loop that moves each character in its final position without performing all the steps.
    You can do this? Any suggestions?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sum of all elements in an array
    By SilentPirate007 in forum C Programming
    Replies: 6
    Last Post: 05-02-2010, 08:32 AM
  2. Sum all odd array elements?
    By Marth_01 in forum C Programming
    Replies: 9
    Last Post: 11-04-2008, 09:47 PM
  3. array of zero elements
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 02-17-2008, 06:10 AM
  4. # of Elements in Array
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-22-2002, 01:43 PM
  5. array rotation?
    By ganja in forum C++ Programming
    Replies: 2
    Last Post: 01-23-2002, 06:34 PM

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