Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "GeneralizedList.h"
- using namespace std;
- GeneralizedList::~GeneralizedList()
- {
- }
- GeneralizedList::GeneralizedList()
- {
- List = NULL;
- }
- GeneralizedList::GeneralizedList(Pixel pxl)
- {
- List = new GenListNode;
- List->isList;
- List->Item.x = pxl.x;
- List->Item.y = pxl.y;
- }
- GeneralizedList::GeneralizedList(GenListNode *subList)
- {
- List = new GenListNode;
- List->Next = NULL;
- List->sublist = subList;
- }
- void GeneralizedList::AddAtom(Pixel pxl)
- {
- GenListNode *pCurr, *pNew;
- pCurr = List;
- if(List == NULL)
- {
- List = new GenListNode;
- List->isList = 0;
- List->Item.x = pxl.x;
- List->Item.y = pxl.y;
- List->Next = NULL;
- }
- else
- {
- while(pCurr->Next != NULL)
- {
- pCurr = pCurr->Next;
- }
- pNew = new GenListNode;
- pNew->isList = 0;
- pNew->Item.x = pxl.x;
- pNew->Item.y = pxl.y;
- pNew->Next = NULL;
- pCurr->Next = pNew;
- }
- }
- void GeneralizedList::AddSubList(GenListNode *subList)
- {
- GenListNode *pCurr, *pNew;
- pCurr = List;
- if(List == NULL)
- {
- List = new GenListNode;
- List->isList = 1;
- List->sublist = subList;
- List->Next = NULL;
- }
- else
- {
- while(pCurr->Next != NULL)
- {
- pCurr = pCurr->Next;
- }
- pNew = new GenListNode;
- pNew->isList = true;
- pNew->sublist = subList;
- pNew->Next = NULL;
- pCurr->Next = pNew;
- }
- }
- int GeneralizedList::Length()
- {
- GenListNode *pCurr;
- int length = 0;
- pCurr = List;
- while(pCurr != NULL)
- {
- if(pCurr->isList)
- {
- length += Length(pCurr->sublist);
- }
- else
- {
- length += 1;
- }
- pCurr = pCurr->Next;
- }
- return length;
- }
- int GeneralizedList::Length(GenListNode *subList)
- {
- GenListNode *pCurr = subList;
- int length = 0;
- while(pCurr != NULL)
- {
- if(pCurr->isList)
- {
- Length(pCurr->sublist);
- }
- else
- {
- length += 1;
- }
- pCurr = pCurr->Next;
- }
- return length;
- }
- void GeneralizedList::Traverse()
- {
- GenListNode *pCurr = List;
- while(pCurr != NULL)
- {
- if(pCurr->isList)
- {
- Traverse(pCurr->sublist);
- }
- else
- {
- cout << "(" << pCurr->Item.x << ", " << pCurr->Item.y << ")";
- }
- pCurr = pCurr->Next;
- }
- }
- void GeneralizedList::Traverse(GenListNode *subList)
- {
- GenListNode *pCurr = subList;
- while(pCurr != NULL)
- {
- if(pCurr->isList)
- {
- Traverse(pCurr->sublist);
- }
- else
- {
- cout << "(" << pCurr->Item.x << ", " << pCurr->Item.y << ")";
- }
- pCurr = pCurr->Next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement