Thread: Shift right for an array .

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    5

    Shift right for an array .

    Hello there ,

    can anyone write me a function that do shift right once of an array .
    it should be circular.
    the function gets pointer for an array and returns nothing .

    I tried to google it but I didn't find any relevant code.

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    I found the solution :P ..

    left shift
    temp=a[0];
    for(i=0;i<n-a;i++)
    a[i]=a[i+1];
    a[n-1]=temp;


    shift right
    temp=a[n-1];
    for(i=n-1;i>0;i--)
    a[i]=a[i-1];
    a[0]=temp;

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    On the other note, we are here not to write code for you. We are here to help to write your own code.

    ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    5
    I know but when u are out of options you will try anything just to get a solution.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It doesn't really seem like you were out of options. Because it doesn't seem like you used the option called "think about the problem".

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-25-2008, 01:50 AM
  2. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  3. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  4. array shift problem
    By splendid bob in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2002, 10:11 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM