Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct TT
- {
- int n; // offset
- int nLen; // strlen
- TT *pNext;
- };
- class LL
- {
- public:
- TT *pHead;
- TT *pTail;
- int nCounter;
- char *pszBUF,
- *pszPos; // Ïîçèöèÿ ïå÷àòè íîâîãî ñëîâà
- LL();
- void push(const char* psz);
- void init();
- void monitor();
- } L1;
- int main()
- {
- L1.push( "void");
- L1.push( "one");
- L1.push( "two");
- L1.push( "three");
- L1.push( "SONY");
- L1.monitor();
- return 0;
- }
- LL::LL()
- {
- pHead = 0;
- pTail = 0;
- nCounter = 0;
- }
- /////////////////////////////////////////////////
- void LL::push(const char* psz)
- {
- static int nSizeBuf = 0,
- nStepBuf = 100;
- if(nCounter == 0)
- {
- pszBUF = (char *)malloc (nStepBuf);
- pszPos = pszBUF;
- nSizeBuf = nStepBuf;
- }
- int nLen = strlen(psz);
- // = = = = = = = = = =
- int nOffset = pszPos - pszBUF;
- if(nOffset + nLen >= nStepBuf)
- {
- nSizeBuf += nStepBuf;
- pszBUF = (char *)realloc(pszBUF, nSizeBuf);
- pszPos = pszBUF - nOffset;
- }
- memcpy(pszPos, psz, nLen);
- TT *pp = (TT*)malloc(sizeof(TT));
- // int nOffset = pszPos - pszBUF ;
- pp->n = nOffset;
- pp->nLen = nLen;
- pszPos += nLen; // Íà áóäóùåå
- if(nCounter == 0)
- {
- pHead = pp;
- }
- else
- {
- pTail->pNext = pp;
- }
- nCounter++;
- pp->pNext = 0;
- pTail = pp;
- }
- //////////////////////////////////////////////////
- void LL::monitor()
- {
- TT *p = pHead;
- for(int i = 0; i < nCounter; i++)
- {
- printf("n = %3d, %.*s\n", p->n, p->nLen, L1.pszBUF+p->n);
- p = p->pNext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement