idk why these stuffs get stashed for so long and I didn't ever commit them
This commit is contained in:
40
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.cbp
Normal file
40
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.cbp
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="DancePartner" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/DancePartner" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/DancePartner" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="DancePartner.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
117
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.cpp
Normal file
117
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
|
||||
struct dancer
|
||||
{ string name;
|
||||
char sex;
|
||||
};
|
||||
|
||||
struct Node
|
||||
{ dancer data;
|
||||
Node* next;
|
||||
}*front,*rear;
|
||||
|
||||
struct LinkQueue
|
||||
{ Node *front;
|
||||
Node *rear;
|
||||
}Gentleman, Lady;
|
||||
|
||||
void InitialLinkQueue(LinkQueue& queue)
|
||||
{ queue.front=new Node;
|
||||
queue.front->next=NULL;
|
||||
queue.rear=queue.front;
|
||||
}
|
||||
|
||||
void DeleteLinkQueue(LinkQueue& queue)
|
||||
{ Node *p;
|
||||
while(queue.front!=NULL)
|
||||
{ p=queue.front;
|
||||
queue.front=queue.front->next;
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
void EnQueue(LinkQueue& queue,dancer& value)
|
||||
{
|
||||
Node* s=new Node;
|
||||
s->data=value;
|
||||
s->next=queue.rear->next;
|
||||
queue.rear->next=s;
|
||||
queue.rear=s;
|
||||
}
|
||||
|
||||
int IsEmpty(LinkQueue queue)
|
||||
{
|
||||
if (queue.front==queue.rear) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
dancer DeQueue(LinkQueue &queue)
|
||||
{ dancer x;
|
||||
Node *p;
|
||||
if (IsEmpty(queue)) throw "队列为空,无法出队列!";
|
||||
p=queue.front->next;
|
||||
x=p->data;
|
||||
queue.front->next=p->next;
|
||||
if (p==queue.rear) queue.rear=queue.front;
|
||||
delete p;
|
||||
return x;
|
||||
}
|
||||
|
||||
dancer GetHead(LinkQueue queue)
|
||||
{ if (IsEmpty(queue)) throw "队列为空,无法取得队首元素!";
|
||||
return queue.front->next->data;
|
||||
}
|
||||
|
||||
void QueueTranverse(LinkQueue queue)
|
||||
{ Node *p;
|
||||
p=queue.front->next;
|
||||
while(p!=NULL)
|
||||
{ cout<<(p->data).name<<" ";
|
||||
p=p->next;
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{ cout<<"请输入舞伴总数量:"<<endl;
|
||||
int num;
|
||||
cin>>num;
|
||||
|
||||
InitialLinkQueue(Gentleman);
|
||||
InitialLinkQueue(Lady);
|
||||
|
||||
for(int i=0;i<num;i++)
|
||||
{ cout<<"请输入舞者性别(F(女) or M(男))及姓名:"<<endl;
|
||||
char sex;
|
||||
cin>>sex;
|
||||
string name;
|
||||
cin>>name;
|
||||
dancer newdancer;
|
||||
newdancer.name=name;
|
||||
newdancer.sex=sex;
|
||||
if(sex=='F')
|
||||
EnQueue(Lady,newdancer);
|
||||
if(sex=='M')
|
||||
EnQueue(Gentleman,newdancer);
|
||||
}
|
||||
|
||||
while ( (!IsEmpty(Gentleman)) && (!IsEmpty(Lady)) )
|
||||
cout<<DeQueue(Gentleman).name<<"<---配对--->"<<DeQueue(Lady).name<<endl;
|
||||
if (!IsEmpty(Gentleman))
|
||||
cout<<GetHead(Gentleman).name<<"先生还在等着呢!"<<endl;
|
||||
else
|
||||
if (!IsEmpty(Lady))
|
||||
cout<<GetHead(Lady).name<<"女士还在等着呢!"<<endl;
|
||||
else
|
||||
cout<<"配对完美结束!"<<endl;
|
||||
|
||||
DeleteLinkQueue(Gentleman);
|
||||
DeleteLinkQueue(Lady);
|
||||
|
||||
system("pause");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
5
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.depend
Normal file
5
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.depend
Normal file
@@ -0,0 +1,5 @@
|
||||
# depslib dependency file v1.0
|
||||
1617974749 source:c:\users\86138\desktop\zykathy\dancepartner(Îè°éÎÊÌâ)\dancepartner.cpp
|
||||
<iostream>
|
||||
<string>
|
||||
|
||||
10
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.layout
Normal file
10
OrigFiles/3-特殊线性表/DancePartner(舞伴问题)/DancePartner.layout
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="DancePartner.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1512" topLine="18" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
Reference in New Issue
Block a user