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
c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above
Explain the concept and use of type void.
How are pointers declared in c?
What math functions are available for integers? For floating point?
What is integer constants?
Why do we use namespace feature?
Is c dynamically typed?
what is a constant pointer in C
Should I use symbolic names like true and false for boolean constants, or plain 1 and 0?
What are the features of the c language?
What is the correct declaration of main?
can we change the default calling convention in c if yes than how.........?
Sir i need notes for structure,functions,pointers in c language can you help me please
How does free() know explain how much memory to release?
What are variables and it what way is it different from constants?