Thread: Rotation of elements of an array

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

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, 10:47 PM
  3. array of zero elements
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 02-17-2008, 07: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, 07:34 PM