Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- struct nodeStruct
- {
- int valX, valY;
- struct nodeStruct* next;
- };
- typedef struct nodeStruct node;
- void push(node** hd, int vx, int vy){
- node* temp;
- temp = (node*)malloc(sizeof(node));
- temp -> valX = vx;
- temp -> valY = vy;
- temp -> next = *hd;
- *hd = temp;
- }
- void pop(node** hd){
- if(hd == NULL){
- printf("%s %c", "No solution available, exiting program.");
- exit(-1);
- }
- node* temp = (*hd) -> next;
- free(*hd);
- if(temp == NULL){
- printf("%s %c", "No solution available, exiting program.");
- exit(-1);
- }
- *hd = temp;
- }
- int main(int argc, char **argv){
- node* p = NULL;
- push(&p, 1, 5);
- push(&p, 3, 6);
- pop(&p);
- printf("%i %s %i\n", p->valX, " ", p->valY/*, " ", p->next->valX, " ", p->next->valY*/);
- push(&p, 4, 9);
- printf("%i %s %i %s %i %s %i\n", p->valX, " ", p->valY, " ", p->next->valX, " ", p->next->valY);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement