Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A 3-dimensional NX NX N array has to be rotated by K-times. One rotation is a combination of two operations, a backward rotation followed by a forward rotation. Backward rotation considers elements lying in the plane formed by joining indices [0][0][0], [N-1][0][N−1], [N−1][N−1][N-1], and [0][N-1][0]. Similarly, for Forward rotation elements lying in the plane formed by joining indices [N-1][0][0], [0][0][N−1], [0][N−1][N-1], and [N−1][N-1][0] are considered. The starting points for Backward and Forward rotations are [0][0][0] and [N-1][0][0], respectively. Rotation by K = 1 in a 3 x 3 x 3 array changes the content.

What I have tried:

tried all sorts of arrays and algorithms.
C++
#include<iostream>
using namespace std;

class node
{
    public:
        int data;
        node* next;
        node* prev;
};

node* head=NULL;

void print()
{
    node* p=head;
    while(p!=NULL)
    {
        cout<<p->data<<" ";
        p=p->next;
    }
}
node* pushtail()
{
    int data;
    cin>>data;
    node* newnode=(node)malloc(sizeof(node));
    newnode->data=data;
    newnode->next=NULL;

    if(head==NULL)
    {
        head=newnode;
        newnode->prev=NULL;
    }
    else 
    {
        node p=head;
        while(p->next!=NULL)
            p=p->next;

        p->next=newnode;
        newnode->prev=p;
    }

    return head;
}

node* pushhead()
{
    int data;
    cin>>data;
    node* newnode=(node*)malloc(sizeof(node));
    newnode->data=data;
    newnode->prev=NULL;
    newnode->next=head;
    head=newnode;

    return head;
}

int main()
{
    int n,data;
    cin>>n;

    for(int i=0;i
Posted
Updated 18-Sep-22 19:51pm
v3
Comments
Patrice T 19-Sep-22 1:40am    
Show your work so far.
Patrice T 19-Sep-22 1:46am    
Use Improve question to update your question.
jeron1 19-Sep-22 10:12am    
Part of your problem is you haven't asked a question.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

And by the way ... it may be urgent to you, but it isn't to us. All that your stressing the urgency does is to make us think you have left it too late, and want us to do it for you. This annoys some people, and can slow a response.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900