Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Netscape stack implementation

    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:
    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);
    }
    }
    Last edited by oracleguy; 10-08-2008 at 07:33 PM.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I assume you haven't solved your problem and removed the resolve flag on your thread.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •