C++编程试题求解

来源:百度知道 编辑:UC知道 时间:2024/06/20 11:05:46
编写函数,作用是把一个char组成的字符串循环右移n个。比如原来是“abcdefghi”如果n=2,移位后应该是“hiabcdefgh”

求一个答案,万谢!

#include<iostream>
using namespace std;

struct node //a struct of type node
{
char item;
node *next;
};
node *head;
node *ptr = head;

void creatList()
{
cout << "Enter a sequence of charactors and end with &:"<<endl;
node *head=NULL;
node *tail;
char i;
cin >> i;
if (i != '&')
{
head = new node;
head->item = i;
head->next = head;
tail = head; //first node
cin >> i; //cin next integer
while (i != '&')
{
tail->next = new node;
tail = tail->next;
tail->item = i;
tail->next = head;
cin >> i;
}
}

cout << "The charactor in the list are: "<<endl;
node *c = head;

do {
cout<<c->item<<" ";