Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct element {
- int data;
- struct element *p;
- };
- void addElement(struct element **cur) {
- struct element *memory;
- memory=(struct element *) malloc(sizeof(struct element));
- memory->data=rand()%100+1;
- memory->p=NULL;
- if (*cur) {
- (*cur)->p=memory;
- }
- *cur=memory;
- }
- void removeElement(struct element **cur) {
- struct element *memory=(*cur)->p;
- free(*cur);
- *cur=memory;
- }
- int main()
- {
- struct element *start=NULL, *end=NULL;
- addElement(&end);
- start=end;
- addElement(&end);
- addElement(&end);
- addElement(&end);
- removeElement(&start);
- removeElement(&start);
- while (end) {
- printf("%d\n",start->data);
- start=start->p;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement