Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the difference between struct and union in C?

1257


How can you increase the size of a statically allocated array?

1047


What is indirection? How many levels of pointers can you have?

1096


what is the diffrenet bettwen HTTP and internet protocol

1797


string reverse using recursion

2394


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

997


i want to know the procedure of qualcomm for getting a job through offcampus

2423


How can I recover the file name given an open stream or file descriptor?

1044


Why c is called top down?

1105


hi to every one .. how to view table pool after creating the pooled table? plz help me.. if any knows abt this ..

1875


Write a c program to demonstrate character and string constants?

2131


What are the string functions? List some string functions available in c.

955


What is an operator?

1027


main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }

1472


Why isn't it being handled properly?

1014