-
-
Save defrindr/9049f8be6839b6d680f31bf7aae48039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <limits.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define max 100 | |
struct Stack { | |
char* origin; | |
int count; | |
int top; | |
unsigned capacity; | |
} Stack; | |
struct Stack* createStack(unsigned cp){ | |
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack)); | |
stack->capacity = cp; | |
stack->top = -1; | |
stack->origin = (char*)malloc(stack->capacity * sizeof(char)); | |
return stack; | |
} | |
int isFull(struct Stack* stack) | |
{ | |
return stack->top == stack->capacity - 1; | |
} | |
int isEmpty(struct Stack* stack) | |
{ | |
return stack->top == -1; | |
} | |
void push(struct Stack* stack, char item) | |
{ | |
if (isFull(stack)) | |
return; | |
stack->origin[++stack->top] = item; | |
} | |
void print(struct Stack* stack){ | |
printf("%s\n", stack->origin); | |
} | |
char pop(struct Stack* stack) | |
{ | |
if (isEmpty(stack)) | |
return INT_MIN; | |
stack->origin[stack->top] = '\0'; | |
stack->top--; | |
} | |
int main(){ | |
struct Stack* stack = createStack(1000); | |
char str[max]; | |
char* check; | |
char* cmp="*"; | |
fgets(str, max, stdin); | |
int popping = 0; | |
for ( check=&str[0]; *check != '\0'; check++ ) | |
{ | |
int i1 = *cmp; | |
int i2 = *check; | |
if(i1 == i2){ | |
pop(stack); | |
if(popping == 1){ | |
print(stack); | |
} | |
popping = 1; | |
}else{ | |
push(stack, *check); | |
} | |
} | |
// puts(str); | |
// printf("%d", len); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <limits.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define max 100 | |
struct Stack { | |
char* origin; | |
int count; | |
int top; | |
unsigned capacity; | |
} Stack; | |
struct Stack* createStack(unsigned cp){ | |
struct Stack* stack = (struct Stack*)malloc(sizeof(struct Stack)); | |
stack->capacity = cp; | |
stack->top = -1; | |
stack->origin = (char*)malloc(stack->capacity * sizeof(char)); | |
return stack; | |
} | |
int isFull(struct Stack* stack) | |
{ | |
return stack->top == stack->capacity - 1; | |
} | |
int isEmpty(struct Stack* stack) | |
{ | |
return stack->top == -1; | |
} | |
void push(struct Stack* stack, char item) | |
{ | |
if (isFull(stack)) | |
return; | |
stack->origin[++stack->top] = item; | |
} | |
void print(struct Stack* stack){ | |
printf("%s\n", stack->origin); | |
} | |
char pop(struct Stack* stack) | |
{ | |
if (isEmpty(stack)) | |
return INT_MIN; | |
return stack->origin[stack->top--]; | |
} | |
int main(){ | |
struct Stack* stack = createStack(1000); | |
char str[max]; | |
char res[max]; | |
char* check; | |
char* cmp="*"; | |
fgets(str, max, stdin); | |
int popping = 0; | |
int len = strlen(str), i; | |
for ( check=&str[0]; *check != '\0'; check++ ) | |
{ | |
push(stack, *check); | |
} | |
for ( i = 0; i < len; i++ ) | |
{ | |
res[i] = pop(stack); | |
} | |
printf("%s\n", res); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment