The Sqstack for Sequential stack | Data

简介: The some code in Data book (5th Edition) from the 81 page to 82 page

The some code in Data book (5th Edition) from the 81 page to 82 page

Update completed
#define MaxSize 50
typedef int ElemType;

typedef struct{
    ElemType data[MaxSize];
    int top; //Sequential stack top of the stack pointer
} SqStack;

//Initialization Sequential stack
void InitStack(SqStack *&s){  
    s=(SqStack *)malloc(sizeof(SqStack));
    s->top=-1;
}

//Create Sequential stack
void CreateStack(SqStack *&s, int a[], int n) {
    s = (SqStack *)malloc(sizeof(SqStack));
    s->top = -1;
    for (int i = 0; i < n; ++i) {
        s->data[i] = a[i];
    }
    s->top = n-1;
}

//Destroyed Sequential stack
void DestroyStack(SqStack *&s){
    free(s);
}

//Determine if the Sequential stack is empty
bool StackEmpty(SqStack *s){
    return(s->top==-1);
}

//Into stack
bool Push(SqStack *&s, ElemType e){  
    if (s->top==MaxSize-1){//Processing overflow
        return false;
    }
    s->top++;//Top of the stack add 1
    s->data[s->top]=e;//Put element e on the top of the stack pointer
    return true;
}

//Out stack
bool Pop(SqStack *&s, ElemType &e){  
    if (s->top==-1)
    return false;
    e=s->data[s->top];
    s->top--;
    return true;
}

//Get length of sequential stack
int StackLength(SqStack *s) {
    return s->top + 1;
}

//Output sequential stack
void ShowStack(SqStack *s) {
    if (s->top == -1) {
        printf("\n");
        return;
    }
    for (int i = 0; i <= s->top; ++i) {
        printf("%d ", s->data[i]);
    }
    printf("\n");
}
如有侵权,请联系作者删除
目录
相关文章
|
3月前
|
TensorFlow 算法框架/工具
【Tensorflow】解决A `Concatenate` layer should be called on a list of at least 2 inputs
在TensorFlow 2.0中,使用Concatenate函数时出现错误,可以通过替换为tf.concat 来解决。
44 4
|
3月前
|
机器学习/深度学习 TensorFlow 算法框架/工具
【Tensorflow+keras】解决cuDNN launch failure : input shape ([32,2,8,8]) [[{{node sequential_1/batch_nor
在使用TensorFlow 2.0和Keras训练生成对抗网络(GAN)时,遇到了“cuDNN launch failure”错误,特别是在调用self.generator.predict方法时出现,输入形状为([32,2,8,8])。此问题可能源于输入数据形状与模型期望的形状不匹配或cuDNN版本不兼容。解决方案包括设置GPU内存增长、检查模型定义和输入数据形状、以及确保TensorFlow和cuDNN版本兼容。
49 1
|
3月前
|
TensorFlow API 算法框架/工具
【Tensorflow+keras】解决使用model.load_weights时报错 ‘str‘ object has no attribute ‘decode‘
python 3.6,Tensorflow 2.0,在使用Tensorflow 的keras API,加载权重模型时,报错’str’ object has no attribute ‘decode’
54 0
|
6月前
|
存储 算法 前端开发
[C++基础]-stack和queue
[C++基础]-stack和queue
Expected more than 1 value per channel when training, got input size torch.Size
因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。
914 0
The SqQueue for Sequential queue (Continuous updates) | Data
The code in Data book (5th Edition) from the 99 page to 100 page
99 0
The LinkStNode for Linked stack | Data
The code in Data book (5th Edition) from the 83 page to 86 page
114 0
The SqString for Sequential string | Data
The code in Data book (5th Edition) from the 123 page to 126 page
93 0
|
数据可视化 PyTorch 算法框架/工具
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
Pychram Pytorch Tensorboard 报错 “No dashboards are active for the current data set.“ 解决方案
Data Structures (三) - 栈Stack实现
Data Structures (三) - 栈Stack实现
Data Structures (三) - 栈Stack实现