Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Compiler gcc with Code::Block
- #include <stdio.h>
- struct node {
- char ch;
- struct node *next;
- };
- typedef struct node* NODEPTR;
- void Init(NODEPTR *plist) {
- *plist = NULL;
- }
- int Empty(NODEPTR plist) {
- if (plist == NULL )
- return 1;
- return 0;
- }
- void Push(NODEPTR *plist, char chr) {
- NODEPTR p = (NODEPTR) malloc(sizeof(struct node));
- p->ch = chr;
- p->next = NULL;
- if (Empty(*plist))
- *plist = p;
- else {
- p->next = *plist;
- *plist = p;
- }
- }
- void Pop(NODEPTR *plist, char *chr) {
- if (!Empty(*plist)) {
- NODEPTR p = *plist;
- *plist = (*plist)->next;
- *chr = p->ch;
- free(p);
- }
- }
- int main() {
- NODEPTR p;
- Init(&p);
- char st[100];
- printf(" - Enter string: ");
- gets(st);
- int i, n = strlen(st);
- for (i = 0; i < n; i++)
- Push(&p, st[i]);
- for (i = 0; i < n; i++)
- Pop(&p, &st[i]);
- st[n] = '\0';
- printf(" - New string: %s", st);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment