TJU1012

    没什么好说的了,标准链表题。
None.gif#include<iostream>
None.gif
using namespace std;
None.gif
None.gif
class LinkedList
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
public:
InBlock.gif    LinkedList
* Next;
InBlock.gif    
int Number;
InBlock.gif    
int Password;
InBlock.gif    
void DeleteNext();
InBlock.gif    LinkedList
* Append(int Number,int Password);
InBlock.gif    LinkedList(
int Number,int Password);
ExpandedBlockEnd.gif}
;
None.gif
None.gifLinkedList::LinkedList(
int Number,int Password)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
this->Number=Number;
InBlock.gif    
this->Password=Password;
InBlock.gif    
this->Next=this;
ExpandedBlockEnd.gif}

None.gif
None.gif
void LinkedList::DeleteNext()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    LinkedList
* temp=Next;
InBlock.gif    Next
=temp->Next;
InBlock.gif    delete(temp);
ExpandedBlockEnd.gif}

None.gif
None.gifLinkedList
* LinkedList::Append(int Number,int Password)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    LinkedList
* temp
InBlock.gif        
=new LinkedList(Number,Password);
InBlock.gif    temp
->Next=this->Next;
InBlock.gif    
this->Next=temp;
InBlock.gif    
return temp;
ExpandedBlockEnd.gif}

None.gif
None.gif
int main()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    LinkedList
* head;
InBlock.gif    
int Count,people,Count1,password;
InBlock.gif    
//Construct Linked List
InBlock.gif
    while(cin>>people>>Count)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        cin
>>password;
InBlock.gif        head
=new LinkedList(1,password);
InBlock.gif        
for(Count1=2;Count1<=people;Count1++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            cin
>>password;
InBlock.gif            head
=head->Append(Count1,password);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
//Exit Queues
InBlock.gif
        while(head->Next != head)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for(Count1=Count;Count1>1;Count1--)
InBlock.gif                head
=head->Next;
InBlock.gif            cout
<<head->Next->Number<<' ';
InBlock.gif            Count
=head->Next->Password;
InBlock.gif            head
->DeleteNext();
ExpandedSubBlockEnd.gif        }

InBlock.gif        cout
<<head->Number<<endl;
InBlock.gif        delete(head);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return 0;
ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/FancyMouse/articles/219739.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值