- 第一部分:顺序栈的结构体定义,初始化,push,pop,判断空,判断满
- 第二部分:链栈的结构体定义,初始化,push,pop,判断空,没有栈满的情况就不用判断了
- 第三部分:顺序队列(循环队列)的结构体定义,初始化,push,pop,判断空,判断满
- 第四不对:链队的结构体定义,初始化,push,pop,判断空,没有队满的情况就不用判断了
- 括号匹配算法
- 十进制转16进制以下的个各进制算法
- 回文字符串的判断
- 单链表中存放的字符串是否中心对称算法
#include <stdio.h>
#include <stdlib.h>
#define maxsize 100
typedef struct{
int data[maxsize];
int top;
}Stack;
void initStack(Stack ** stack){
(*stack) = (Stack *)malloc(sizeof(Stack));
(*stack) -> top = -1;
}
int isFull(Stack * stack){
if(stack->top == maxsize - 1){
return 1;
}
return 0;
}
int isEmpty(Stack * stack){
if(stack->top == -1){
return 1;
}
return 0;
}
int push(Stack * stack,int e){
if(!isFull(stack)){
stack->data[++(stack->top)] = e;
return 1;
}
return 0;
}
int pop(Stack * stack,int * e){
if(!isEmpty(stack)){
(*e) = stack->data[(stack->top)--];
return 1;
}
return 0;
}
typedef struct Node{
int data;
struct Node * next;
}LStack;
void initLStack(LStack ** stack){
(*stack) = (LStack *)malloc(sizeof(LStack));
(*stack) -> next = NULL;
}
int isEmptyLStack(LStack * stack){
if(stack->next == NULL){
return 1;
}
return 0;
}
void pushLStack(LStack * stack,int e){
struct Node * s = (struct Node *)malloc(sizeof(struct Node));
s -> next = stack->next;
s -> data = e;
stack ->next = s;
}
int popLStack(LStack * stack,int * e){
struct Node * s;
if(!isEmptyLStack(stack)){
s = stack->next;
(*e) = s->data;
stack->next = s->next;
free(s);
return 1;
}
return 0;
}
typedef struct {
int data[maxsize];
int front,rear;
}Queue;
void initQueue(Queue ** que){
(*que) = (Queue *)malloc(sizeof(Queue));
(*que) -> front = 0;
(*que) -> rear = 0;
}
int isFullQue(Queue * que){
if((que->rear + 1)%maxsize == que->front){
return 1;
}
return 0;
}
int isEmptyQue(Queue * que){
if(que->rear == que->front){
return 1;
}
return 0;
}
int inQueue(Queue * que , int e){
if(!isFullQue(que)){
que->rear = (que->rear + 1)%maxsize;
que->data[que->rear] = e;
}
return 0;
}
int deQueue(Queue * que, int * e){
if(isEmptyQue(que)){
que->front = (que->front + 1)%maxsize;
(*e) = que->data[que->front];
return 1;
}
return 0;
}
typedef struct{
struct Node * front;
struct Node * rear;
}LQueue;
void initLQueue(LQueue ** que){
(*que) = (LQueue *)malloc(sizeof(LQueue));
(*que)->front = NULL;
(*que)->rear = NULL;
}
int isEmptyLQueue(LQueue * que){
if(que->rear == NULL || que->front == NULL){
return 1;
}
return 0;
}
void inLQueue(LQueue * que,int e){
struct Node * node = (struct Node *)malloc(sizeof(struct Node));
node -> data = e;
node -> next = NULL;
que->rear->next = node;
}
int deLQueue(LQueue * que,int * e){
struct Node * s = que->front;
if(isEmptyLQueue(que)){
return 0;
}
que->front = s->next;
(*e) = s->data;
free(s);
return 1;
}
int justify(int arr[],int n){
Stack * stack;
initStack(&stack);
int i;
char c;
int e;
for(i=0;i<n;i++){
c = arr[i];
if(c == '('){
push(stack,arr[i]);
}else if(c == ')'){
pop(stack,&e);
}
}
if(isEmpty(stack)){
return 1;
}
return 0;
}
int change(int e,int size){
int new = 0;
int mod = 0;
int w;
LStack * stack;
initLStack(&stack);
while(e != 0){
mod = e%size;
e = e/size;
pushLStack(stack,mod);
}
while(!isEmptyLStack(stack)){
popLStack(stack,&w);
char c;
switch(w){
case 10:
c = 'A';
break;
case 11:
c = 'B';
break;
case 12:
c = 'C';
break;
case 13:
c = 'D';
break;
case 14:
c = 'E';
break;
case 15:
c = 'F';
break;
}
if(w>=10){
printf("%c",c);
}else{
printf("%d",w);
}
}
return new;
}
int isReverseString(char arr[],int n){
int e,v,i;
Stack * stack;
LQueue * que;
initLQueue(&que);
initStack(&stack);
for(i=0;i<n;i++){
push(stack,arr[i]);
inLQueue(que,arr[i]);
}
for(i=0;i<n;i++){
pop(stack,&e);
deLQueue(que,&v);
if(e != v){
return 0;
}
}
return 1;
}
int isCentrosymmetry(char arr[],int n){
LStack * stack;
initLStack(&stack);
int i,w;
for(i=0;i<n;i++){
pushLStack(stack,arr[i]);
}
for(i=0;i<n;i++){
popLStack(stack,&w);
if(w != arr[i]){
return 0;
}
}
return 1;
}
int main(){
return 0;
}