第6章17题

// 6_17.cpp : 试用顺序存储结构设计一个算法,仅用一个辅助节点,实现将线形表中的节点循环右移k位的运算,并分析算法的时间复杂度。
void Rotate(node* head, int k)
{
     if (k <= 0)
     {
          printf("k值小于0,将返回。n");
          return;
     }
     printf("循环右移k位:");
  
     datatype tempdata;
     for (int i = 0; i < k; i++)
     {
          tempdata = head->data[MAX_DATA_SIZE-1];
          for (int j = MAX_DATA_SIZE – 2; j >= 0; j–)
          {
               head->data[j+1]=head->data[j];
          }
          head->data[0]=tempdata;
     }
}
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: