C++单循环链表约瑟夫问题

#include

using namespace std;

class Node
{
public:

Node *next;

char *name;
char *number;
char *sex;
char *age;
char *banji;
char *heal;
/*void input()
{
cin>>name;
cin>>number;
cin>>sex;
cin>>age;
cin>>banji;
cin>>heal;

}
void output()
{
    cout<<name<<" "<<number<<" "<<sex<<" "<<age<<" "<<banji<<" "<<heal<<endl;
}
*/

};
class linklist
{
public:
Node *head;
int n;

linklist()
{
    head=new Node ;
    head->next=NULL;
}
void input3()
{


    Node *t=head;
    Node *q;
    for(int i=0; i<n; i++)
    {
        q=new Node;
        t->next=q;

cin>>q->name>>q->number>>q->sex>>q->age>>q->banji>>q->age>>q->banji>>q->heal;
q->next=NULL;

        t=q;
    }
    q->next=head->next;

}

void johesu(linklist a)
{
    Node *p=a.head->next,*q=a.head->next;
    while(q&&q!=q->next)
    {
        int i=1;
              cin>>n;
        for( i=1; i<n; p=q,q=q->next)
            i++;
        cout<<q->name<<" "<<q->number<<" "<<q->sex<<" "<<q->age<<" "<<q->banji<<" "<<q->age<<" "<<q->banji<<" "<<q->heal<<endl;
        p->next=q->next;
        delete q;
        q=p->next;

    }
    a.head=NULL;

}

};
int main()
{
linklist a;

int m,n,i;
cin>>m;
a.n=m;
a.input3();
a.johesu(a);

}
请大神指出我的代码错误,本人新手,不喜勿喷。。我只是想不断改正自己的代码,发现自己的问题。谢谢!!!!

查看全部
qq_24044961
qq_24044961
2015/09/27 07:03
  • c++
  • 代码
  • 链表
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复