C program to perform stack operation using singly linked list
Answer Posted / bin fang
the above has bugs! for example, the count is not
decremented in Pop function...
I rewrote the Push and Pop code as follows:
node *cur = NULL;
node *head = NULL;
void Push(int info)
{
node *new;
new = (node *)malloc(sizeof(node));
new->data = info;
new->next = NULL;
if (head == NULL)
head = new;
else
cur->next = new;
cur = new;
count++;
}
void Pop(void)
{
node *pre = NULL;
node *temp = head;
while (temp != cur) {
pre = temp;
temp = temp->next;
}
printf("\n\tNode (%d) is deleted.", cur->data);
free(cur);
count--;
cur = pre;
if (cur)
cur->next = NULL;
else
head = NULL;
}
| Is This Answer Correct ? | 10 Yes | 1 No |
Post New Answer View All Answers
What is the difference between struct and union in C?
How can you increase the size of a statically allocated array?
What is indirection? How many levels of pointers can you have?
what is the diffrenet bettwen HTTP and internet protocol
string reverse using recursion
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
i want to know the procedure of qualcomm for getting a job through offcampus
How can I recover the file name given an open stream or file descriptor?
Why c is called top down?
hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..
Write a c program to demonstrate character and string constants?
What are the string functions? List some string functions available in c.
What is an operator?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
Why isn't it being handled properly?