Apparently I've sealed off any leaks when calling the FreeStack(stackADT stack) function. The _CrtDumpMemoryLeaks() function is for Visual Studio and it indicates if there is a memory leak. I tested the code below as such: #include My concern is with the bottom function (FreeStack). Obviously I'm not completely finished (needs a pop function). Start by freeing the elements on the stack This function frees the storage associated with the stack This function pops the top element from the stack and returns *((stack->elements) + oldCount) = element Now we push the element onto the stack Stack->elements = (stackElementT*)(malloc((3*oldCount/2)*sizeof(stackElementT))) įor(i = 0 i elements) + i) = *(temp + i) Recreate the stack with a 50% increase in size/capacity Temp = (stackElementT*)(malloc((oldCount)*sizeof(stackElementT))) temp will be the same size as the old stack a transfer, resize, and retransfer, then push A temporary array that we may use later on Void Push(stackADT stack, stackElementT element) This function pushes the specified element onto the stack Functions to determine if stack is empty or full Printf("count = %d\nsize = %d\n",stack->count,stack->size) StackElementT GetStackElement(stackADT stack, int index) the stack, where the top is defined as index 0 This function returns the element a the specified index in Returns the number of elements currently pushed Stack->elements = (stackElementT*)(malloc(50*sizeof(stackElementT))) Stack = (stackCDT*)(malloc(sizeof(stackCDT))) This function allocates and returns a new stack, which is The stackADT represents the abstract type used to store I've implemented a stack in C, using a stackADT struct and a set of functions: #ifndef _stack_h
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |