![]() |
| | #1 |
| Registered User Join Date: Oct 2002
Posts: 92
| Stack 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 | |
| | #2 |
| Registered User 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");
}
}
Fixed by Salem
__________________ AbHHinaay |
| planet_abhi is offline | |
| | #3 |
| +++ OK NO CARRIER 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 | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |