Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://vk.com/evgenykravchenko0
- ___ ___ ___
- / /\ ___ / /\ / /\
- / /:/_ /__/\ / /:/_ / /:/_
- / /:/ /\ \ \:\ / /:/ /\ / /:/ /\
- / /:/ /:/_ \ \:\ / /:/_/::\ / /:/ /:/_
- /__/:/ /:/ /\ ___ \__\:\ /__/:/__\/\:\ /__/:/ /:/ /\
- \ \:\/:/ /:/ /__/\ | |:| \ \:\ /~~/:/ \ \:\/:/ /:/
- \ \::/ /:/ \ \:\| |:| \ \:\ /:/ \ \::/ /:/
- \ \:\/:/ \ \:\__|:| \ \:\/:/ \ \:\/:/
- \ \::/ \__\::::/ \ \::/ \ \::/
- \__\/ ~~~~ \__\/ \__\/
- ___
- /__/\ ___ ___
- \ \:\ / /\ / /\
- \ \:\ / /:/ / /:/
- _____\__\:\ /__/::\ /__/::\
- /__/::::::::\ \__\/\:\__ \__\/\:\__
- \ \:\~~\~~\/ \ \:\/\ \ \:\/\
- \ \:\ ~~~ \__\::/ \__\::/
- \ \:\ /__/:/ /__/:/
- \ \:\ \__\/ \__\/
- \__\/
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_SIZE 50
- char* push ( char *str, int *p);
- void status ( char *str, int elem);
- char* pop ( char *str, int *p);
- int main ( int argc, const char * argv[]) {
- int elem = 0;
- int *p;
- p = &elem;
- char *str = NULL;
- int pressed_key = 0;
- do {
- printf(" MENU\n");
- printf("1. Add symbol in queue..\n");
- printf("2. Queue status..\n");
- printf("3. Delete symbol from queue..\n");
- printf("4. Exit..\n\n");
- printf("Enter number.. - ");
- scanf("%d", &pressed_key);
- if (pressed_key == 1) {
- str = push(str, p);
- printf("\n%d", elem);
- }
- if (pressed_key == 2) {
- status(str, elem);
- printf("\n%d", elem);
- }
- if (pressed_key == 3) {
- str = pop(str, p);
- printf("\n%d", elem);
- }
- } while (pressed_key != 4);
- return 0;
- }
- char* push (char *str, int *p) {
- if (MAX_SIZE == *p) {
- printf("\nQueue is full.\n");
- getchar();
- getchar();
- }
- else {
- printf("\n\nEnter symbol to add in queue: ");
- if (str == NULL) {
- str = (char*)malloc((*p + 1) * sizeof(char));
- }
- else
- str = (char*)realloc(str, (*p + 1) * sizeof(char));
- scanf(" %c", &str[*p]);
- *p += 1;
- }
- return str;
- }
- void status( char *str, int elem) {
- if (elem == 0) {
- printf("\nQueue is empty.\n\n");
- }
- else
- printf("\n Queue: ");
- for (int i = 0; i < elem; i++) {
- printf("%c", str[i]);
- }
- getchar();
- getchar();
- printf("\n");
- }
- char* pop (char *str, int *p) {
- if (*p != 0) {
- char *temp = str;
- char *arr;
- printf("Deleted element: ");
- printf("\n%p\n", temp);
- printf("%p\n", str);
- if (str != NULL) {
- printf("%c\n", *temp);
- }
- for (int i = 1; i < *p; i++) {
- str[i - 1] = str[i];
- }
- *p -= 1;
- arr = (char*)malloc(*p * sizeof(char));
- for (int i = 0; i < *p; i++) {
- arr[i] = str[i];
- }
- free(str);
- str = (char*)malloc(*p * sizeof(char));
- for (int i = 0; i < *p; i++) {
- str[i] = arr[i];
- }
- }
- else {
- printf(" \nQueue is empty\n");
- }
- getchar();
- getchar();
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement