Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct TT
- {
- int n;
- TT *pNext;
- };
- TT *pHead = 0,
- *pTail = 0;
- int nCounter = 0;
- void push(int n);
- ////////////////////////////////////////////////////////////////////
- int main() //
- {
- push(101);
- push(102);
- push(103);
- printf("nCounter = %d\n", nCounter);
- TT *p = pHead;
- for(int i = 0; i < nCounter; i++) // nCounter
- {
- printf("%d, ", p->n);
- p = p -> pNext;
- }
- }
- ////////////////////////////////////////////////////////////////////
- void push(int n)
- {
- TT *p = (TT*)malloc(sizeof(TT));
- p ->n = n;
- if(nCounter == 0) pHead = p;
- else pTail -> pNext = p;
- p->pNext = 0;
- nCounter ++;
- pTail = p;
- }
- /*
- #include <stdio.h>
- struct TT
- {
- int n;
- TT *pNext;
- };
- TT t1, t2;
- ////////////////////////////////////////////////////////////////////
- int main() //
- {
- TT t3, t4;
- t1.n = 1;
- t2.n = 2;
- t3.n = 3;
- t4.n = 4;
- t1.pNext = &t2;
- t2.pNext = &t3;
- t3.pNext = &t4;
- t4.pNext = 0;
- int x;
- TT *pt = &t1;
- for(int i = 0; i < 4; i++)
- {
- printf("address = %d, ", pt);
- printf("%d \n", pt->n);
- pt = pt->pNext;
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement