Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int x;
- Node *pNext;
- };
- struct List
- {
- Node *pHead, *pTail;
- };
- void CreateList(List &L)
- {
- L.pHead = L.pTail = NULL;
- }
- Node *CreateNode(int x)
- {
- Node *p = new Node;
- if (p == NULL) exit(1);
- p->x = x;
- p->pNext = NULL;
- return p;
- }
- void AddTail(List &L, Node *p)
- {
- if (L.pHead == NULL)
- {
- L.pHead = L.pTail = p;
- }
- else
- {
- L.pTail->pNext = p;
- L.pTail = p;
- }
- }
- void Input(List &L)
- {
- Node *p;
- int x;
- do
- {
- cout << " nhap x(0 de ket thuc): ";
- cin >> x;
- if (x == 0) break;
- p = CreateNode(x);
- AddTail(L, p);
- } while (1);
- }
- void Output(List L)
- {
- Node *p = L.pHead;
- while (p != NULL)
- {
- cout << p->x << endl;
- p = p->pNext;
- }
- }
- void main()
- {
- List L;
- CreateList(L);
- Input(L);
- cout << endl;
- Output(L);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement