Exemple #1
0
int main()
{
  char* input;

  for (; fgets(input, 10, stdin) != NULL; ) {
    if (strstr(input, "pop")) {
      popall();
    } else {
      push(atoi(input));
      printf("push(%d)\n", atoi(input));
    }
  }

  return 0;
}
Exemple #2
0
int main()
{
	int flag = 0;
	int c;
	do{
		c = getchar();
		if(!flag){
			putchar(c);
			if(!isalpha(c))
				flag = 1;
		}
		else{
			if(isalpha(c))
				push(c);
			else{
				popall();
				putchar(c);
				flag = 0;
			}			
		}
	}while(c != '.');

	return 0;
}
Exemple #3
0
int main()
{
	init();//created memory

	//creating 10 stacks - removal of each iteration will occur
	Node* stack = myMalloc(10 * (sizeof(Node)));
	for (int i = 0; i < 10; i++)
	{
		stack[i].data = NULL;
		stack[i].next = &stack[i];
		stack[i].end = BORDER;
	}

	//printf("memory\n");
	//for (int i = 0; i < MEMSIZE - 1; i++)
	//	printf("%d ", ((int*)memory)[i]);
	//printf("\n");

	int element = 0;
	int iteration = 0;
	int time = 0; //iteration currently
	int ar1 = 0;//the number of arrays

	clock_t t = clock();
	//the program runs 1 minute
	while (time < 60)
	{
		for (int i = 0; i < 11; i++)
		{
			if (time / 10 >= i && time / 10 % (i + 1) == 0)
			{
				popall(stack + i);
				stack[i].data = NULL;
				stack[i].next = &stack[i];
				stack[i].end = BORDER;
				/*
				printf("memory\n");
				for (int j = 0; j < MEMSIZE - 1; j++)
				printf("%d ", ((int*)memory)[j]);
				printf("\n");*/
			}
		}

		//Array of arrays - creating a count of arrays with different lifetime and with different length
		ar1 = rand() % 10 + 0;
		for (int i = 0; i < ar1; i++)
		{
			int sizearray = rand() % 100 + 0;
			int *array = (int*)myMalloc(sizearray * sizeof(int));
			if (array == NULL)
			{
				printf("The memory ended. The program continues to run without writing into memory the data.");
			}
			else{
				for (int j = 0; j < sizearray; j++)
				{
					array[j] = sizearray;
				}
				int timedelete = (rand() % 10 + 0);
				//push stack
				Node tmp;
				tmp.data = array; //Set the value to 
				tmp.next = stack + timedelete; //Make it so that he was referring to the previous item 
				tmp.end = BORDER;
				stack[timedelete] = tmp; //Now the top of the stack points to the new node. 
			}
		
		}

		printf("Memory now\n");
		for (int j = 0; j < MEMSIZE - 1; j++)
			printf("%d ", ((int*)memory)[j]);
		printf("\n");

		time += 10;

		while (time >(t / CLOCKS_PER_SEC))
		{
			t = clock();
			printf("%f, Wait 10 seconds\n ", ((float)t) / CLOCKS_PER_SEC);

		};


	}
	printf("Memory now\n");
	for (int i = 0; i < MEMSIZE - 1; i++)
		printf("%d ", ((int*)memory)[i]);
	printf("\n"); 

	free(memory);

	printf("The program ended successfully");
	return 0;
}