
Patrick B. answered 08/26/20
Math and computer tutor/teacher
#include <stdio.h>
#include <stdlib.h>
/* Queue data structure:
/* Puts integer x onto the back of array A and increases the nSize counter */
int Array_Push( int * A, int x, int * nSize)
{
int N = *nSize;
int iReturn=0;
int * tempArray =(int*) realloc(A,(N+1)*sizeof(int));
if (N==0)
{
A[0] = x;
(*nSize)=1;
}
else
{
if (tempArray != NULL)
{
tempArray[N] = x; //ingter added here
A = tempArray;
tempArray = NULL;
(*nSize)++;
}
else
{
iReturn = -1;
}
}
return(iReturn);
}
int main()
{
int * A = (int *) malloc(sizeof(int));
A[0]=0;
int nCount=0;
int iNum=0;
while (iNum!=-1)
{
printf(" Please input the # :>");
scanf("%d",&iNum);
Array_Push(A,iNum,&nCount);
}
for (int iLoop=nCount-1; iLoop>=0; iLoop--)
{
printf("%d ",A[iLoop]);
}
free(A);
}
Dorsa R.
thanks but can you write it without using arrays ? and with recursive function if its possible ?08/26/20