...

View Full Version : stack implementation



anis_ahmad
10-08-2008, 08:48 AM
I am trying to write a program for stack implementation through linked list but it is giving an error message: "can not convert void * to node *".The code is given below please help to solve my problem.

code:


#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include"malloc.h"
struct node{
int data;
struct node *link;
};
struct node *top;
void main()
{
int will=1,i,numb;
int pop();
void push(int);
void display();
top=NULL;
clrscr();
printf("program for stack linked list demo\n\n");
while(will==1)
{
printf("MAIN MENU\n\n 1. push insert element on the stack\n 2. pop delete item from stack\n");
scanf("%d",&will);
switch(will)
{
case 1:
printf("enter the data....\n");
scanf("%d",&numb);
push(numb);
display();
break;
case 2:
i=pop();
printf("returned value from pop is %d\n",i);
break;
default:
printf("invalid choice\n ");
}
printf("do you want to continue \n" " 1 for yes and any other key to exit\n");
scanf("%d",&will);
}
}
void push(int y)
{
struct node *x;
x=malloc(sizeof(struct node));
printf("address of newly created node is %d",x);
x->data=y;
x->link=top;
top=x;
}
void display()
{
int i=0;
struct node *temp;
temp=top;
while(temp!=NULL)
{
printf("Item no. is %d : Data %d Link %d",i++,temp->data,temp->link);
temp=temp->link;
}
}
int pop()
{
int a;
if(top==NULL)
{
printf("stack empty\n");
return 0;
}
else
{
a=top->data;
printf("the returned value is %d",a);
free(top);
top=top->link;
return(a);
}
}

:)

oracleguy
10-08-2008, 07:33 PM
I assume you haven't solved your problem and removed the resolve flag on your thread.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum