C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-12-2003, 12:01 AM   #1
Registered User
 
planet_abhi's Avatar
 
Join Date: Oct 2002
Posts: 92
Stack

I want to implement satck in a c program ,i get the functions but they can't run properly same case for queue also anyone help?
the function are as
Code:
typedef struct t_stack *stack;

stack ConsStack( int max_items, int item_size );
/* Construct a new stack
   Pre-condition: (max_items > 0) && (item_size > 0)
   Post-condition: returns a pointer to an empty stack
*/

void Push( stack s, void *item );
/* Push an item onto a stack
   Pre-condition: (s is a stack created by a call to ConsStack) &&
                  (existing item count < max_items) &&
                  (item != NULL)
   Post-condition: item has been added to the top of s
*/

void *Pop( stack s );
/* Pop an item of a stack
   Pre-condition: (s is a stack created by a call to 
                  ConsStack) &&
                  (existing item count >= 1)
   Post-condition: top item has been removed from s
*/
__________________
AbHHinaay
planet_abhi is offline   Reply With Quote
Old 04-12-2003, 04:17 AM   #2
Registered User
 
planet_abhi's Avatar
 
Join Date: Oct 2002
Posts: 92
stack again...

i get the stack function correctly and make a .h file of that now i want to implement them in main program .what should i do?
my program is :
Code:
#include<stdio.h>
#include "mystack.h"

void push(Stack *S, float val)
{
    S->v[ S->top ] = val; 
   (S->top)++;    
/*  Equivalent to: S->v[ (S->top)++ ] = val;   */
}

float pop(Stack *S)
{
    (S->top)--;
    return (S->v[S->top]);
/*  Equivalent to: return (S->v[--(S->top)]);  */
}

void init(Stack *S)
{
    S->top = 0;
}

int full(Stack *S)
{
    return (S->top >= 20);
}

void MyStackPrint(Stack *S)
{
    int i;
    if (S->top == 0)
       printf("Stack is empty.\n");
    else
    {
       printf("Stack contents: ");
       for (i=0;i<S->top;i++)
       {
          printf("%g  ",S->v[i]); 
       }
       printf("\n");
    }
}
http://cboard.cprogramming.com/misc....bbcode#buttons
Fixed by Salem
__________________
AbHHinaay
planet_abhi is offline   Reply With Quote
Old 04-12-2003, 04:22 AM   #3
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,619
What do you mean you want to use it in the main program? Ok, so stick it in there and use it. I'm not sure what the question is. You made a stack, assuming it works, where's the problem? Whenever you need a stack, throw it in, create and instance, and call the functions at the needed times.

Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
stack and pointer problem ramaadhitia C Programming 2 09-11-2006 11:41 PM
Question about a stack using array of pointers Ricochet C++ Programming 6 11-17-2003 10:12 PM
error trying to compile stack program KristTlove C++ Programming 2 11-03-2003 06:27 PM
What am I doing wrong, stack? TeenyTig C Programming 2 05-27-2002 02:12 PM
Stack Program Here Troll_King C Programming 7 10-15-2001 05:36 PM


All times are GMT -6. The time now is 04:00 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22