양 방향 훈련 링크 만 들 기
991 단어 C++기본
#include
using namespace std;
struct BiD_LNode
{
int data;
BiD_LNode *next;
BiD_LNode *prior;
};
//
void Create_LinkList(BiD_LNode *&head)
{
head = new BiD_LNode();
head->prior = head->next = head;
BiD_LNode *p = head;
int data;
while (cin >> data)
{
BiD_LNode *q = new BiD_LNode();
q->data = data;
p->next = q;
q->prior = p;
q->next = head;
head->prior = q;
p = q;
}
}
//
void Print_LinkList(BiD_LNode *&head)
{
//
BiD_LNode *p = head->next;
while (p != head)
{
cout << p->data << " ";
p = p->next;
}
//
/*BiD_LNode *p = head->prior;
while (p != head)
{
cout << p->data << " ";
p = p->prior;
}*/
}
int main()
{
BiD_LNode *head = NULL;
int count = 0;
Create_LinkList(head);
Print_LinkList(head);
system("pause");
return 0;
}