Advertisement
Guest User

Untitled

a guest
Nov 5th, 2012
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct nodeStruct
  6. {
  7.     int valX, valY;
  8.     struct nodeStruct* next;
  9. };
  10.  
  11. typedef struct nodeStruct node;
  12.  
  13. void push(node** hd, int vx, int vy){
  14.     node* temp;
  15.     temp = (node*)malloc(sizeof(node));
  16.     temp -> valX = vx;
  17.     temp -> valY = vy;
  18.     temp -> next = *hd;
  19.     *hd = temp;
  20. }
  21.  
  22. void pop(node** hd){
  23.     if(hd == NULL){
  24.         printf("%s %c", "No solution available, exiting program.");
  25.         exit(-1);
  26.     }
  27.     node* temp = (*hd) -> next;
  28.     free(*hd);
  29.     if(temp == NULL){
  30.         printf("%s %c", "No solution available, exiting program.");
  31.         exit(-1);
  32.     }
  33.     *hd = temp;
  34. }
  35.  
  36. int main(int argc, char **argv){
  37.     node* p = NULL;
  38.     push(&p, 1, 5);
  39.     push(&p, 3, 6);
  40.     pop(&p);
  41.     printf("%i %s %i\n", p->valX, " ", p->valY/*, " ", p->next->valX, " ", p->next->valY*/);
  42.     push(&p, 4, 9);
  43.     printf("%i %s %i %s %i %s %i\n", p->valX, " ", p->valY, " ", p->next->valX, " ", p->next->valY);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement