Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.facebook.com/AminproPastebin
- 1. Initializing a node/inserting etc. Char Val is your data!
- struct node *initialize(char val){
- struct Node *temp;
- temp = (struct Node *)malloc(sizeof(struct Node));
- temp -> key = val;
- temp -> next = NULL;
- return (temp);
- }
- 2. Check if Stack is empty; Will return 1 if empty!
- char empty(struct Node *head, struct Node *tail){
- if(head -> next == tail)
- return 1;
- else
- return 0;
- }
- 3. Pushing a data
- void push (char val, struct Node *head){
- struct Node *temp;
- temp = initialize(val);
- temp -> next = head -> next;
- head -> next = temp;
- }
- 4. Popping a data
- char pop(struct Node *curr){
- struct node *temp;
- char val;
- val curr -> next -> key;
- temp = curr -> next;
- curr -> next = curr -> next -> next;
- free(temp);
- return(val); // return the popped data
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement