当前位置: 首页 > news >正文

WordPress是什么编写信息流优化师面试常见问题

WordPress是什么编写,信息流优化师面试常见问题,长春建网站公司,免费seo网站诊断栈和队列之(栈的基本操作) 实验目的:实验内容:实验结果:实验报告:(及时撰写实验报告):实验测试结果:代码实现1.0:(C/C)【含注释】代码…

栈和队列之(栈的基本操作)

  • 实验目的:
  • 实验内容:
    • 实验结果:
    • 实验报告:(及时撰写实验报告):
      • 实验测试结果:
      • 代码实现1.0:(C/C++)【含注释】
      • 代码实现2.0:(优化 且 纯C版本)
  • 实现十进制数与其它进制数的转换
        • 代码实现:
        • 测试结果:

实验目的:

1.掌握栈的顺序存储结构和链式存储结构
2.实现栈的基本操作,包括栈的建立、求长度、取栈顶元素、入栈、出栈、判栈空 等函数

实验内容:

1.完成顺序栈的建立
2.实现顺序栈的入栈
3.实现顺序栈的出栈
4.判断顺序栈是否为空
5.实现取栈顶元素
6. 实现十进制数与其它进制数的转换

实验结果:

每个同学都要记录实验结果(无论对与错),如果程序调试中有什么错误,记录并分析原因,必须另寻时间调试成功。

实验报告:(及时撰写实验报告):

实验测试结果:

在这里插入图片描述

代码实现1.0:(C/C++)【含注释】

#define SIZE_MAX 2  //初始栈容量
#define STACK_INCREMENT 5  //扩容增量
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
using namespace std;typedef int datatype;//top减base为有效元素个数
typedef struct Stack
{datatype* top;//top指向栈顶元素的下一个地址datatype* base;//栈底int capacity;//容量
}ST;void InitStack(ST& head)
{datatype* tmp = (datatype*)malloc(sizeof(datatype) * SIZE_MAX);if (tmp == NULL) return;//都指向首地址head.top = head.base = tmp;head.capacity = SIZE_MAX;
}void DestroyStack(ST& head)
{free(head.base);head.base = head.top = NULL;head.capacity = 0;
}bool EmptyStack(ST& head)
{return head.base == head.top;
}
bool OverflowStack(ST& head)
{if (head.top - head.base == head.capacity)return true;return false;
}
void Push(ST& head, datatype x)
{if (OverflowStack(head)){datatype* tmp = (datatype*)realloc(head.base, sizeof(datatype) * (head.capacity + STACK_INCREMENT));if (tmp == NULL) return;head.base = tmp;//扩容后恢复原来指针指向,更新容量head.top = head.base + head.capacity;head.capacity += STACK_INCREMENT;}*head.top++ = x;
}
void PopTop(ST& head)
{if (EmptyStack(head)) return;head.top--;
}
datatype GetTop(ST& head)
{if (!EmptyStack(head))return *(head.top - 1);
}
int SizeStack(ST& head)
{if(!OverflowStack(head))return head.top - head.base;
}int main()
{ST head;InitStack(head);Push(head, 1);Push(head, 2);Push(head, 3);Push(head, 4);while (!EmptyStack(head)){cout << "输出当前栈顶元素:" << GetTop(head) << endl;PopTop(head);cout << "栈里剩余元素个数:" << SizeStack(head) << endl << endl;}DestroyStack(head);return 0;
}

代码实现2.0:(优化 且 纯C版本)

  1. 优化:动态2倍扩容
  2. 与1.0版本对栈的实现区别:这里的top也是指向栈顶元素下一个位置,其类型为整形(即下标)

stack.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<stdbool.h>
typedef int STDataType;
typedef struct Stack
{STDataType* a;int top;int capacity;
}ST;
void STInite(ST *ps);
void STDestroy(ST* ps);void STPush(ST* ps, STDataType x);
void STPop(ST* ps);
int STSize(ST* ps);
bool STEmpty(ST* ps);
STDataType STTop(ST* ps);

stack.c

#include"stack.h"
void STInite(ST* ps)
{assert(ps);ps->a = (STDataType*)malloc(sizeof(STDataType) * 3);if (ps->a==NULL){perror("malloc fail");return;}ps->capacity = 3;ps->top = 0;//栈顶为top前一个元素//ps->top = -1;//栈顶为top元素
}
void STDestroy(ST* ps)
{assert(ps);free(ps->a);ps->a = NULL;ps->capacity = 0;ps->top = 0;
}void STPush(ST* ps, STDataType x)
{assert(ps);if (ps->capacity == ps->top){STDataType *tmp = (STDataType*)realloc(ps->a, sizeof(STDataType) * ps->capacity*2);if (tmp == NULL){perror("realloc fail");return;}ps->a = tmp;ps->capacity =ps->capacity * 2;}ps->a[ps->top++] = x;//ps->top++;
}
void STPop(ST* ps)
{assert(ps);assert(!STEmpty(ps));ps->top--;
}
int STSize(ST* ps)
{assert(ps);return ps->top;
}
bool STEmpty(ST* ps)
{assert(ps);return ps->top == 0;
}
STDataType STTop(ST* ps)
{assert(ps);assert(!STEmpty(ps));return ps->a[ps->top - 1];
}

text.c

#include"stack.h"
int main()
{ST st;STInite(&st);STPush(&st, 1);STPush(&st, 2);STPush(&st, 3);STPush(&st, 4);while (!STEmpty(&st)){printf("输出当前栈顶元素:%d\n", STTop(&st));STPop(&st);printf("栈里剩余元素个数:%d\n\n", STSize(&st));}STDestroy(&st);return 0;
}

实现十进制数与其它进制数的转换

代码实现:
void conversion()
{int num, x;cout << "请输入要转化的十进制数字:" << endl;cin >> num;cout << "期望将它转化为几进制数" << endl;cin >> x;cout << "将十进制数 " << num  << " " << "转化为 " << x << " " << "进制数得到的结果为:" << endl;ST st;InitStack(st);while (num > 0){Push(st, num % x);num /= x;}while (!EmptyStack(st)){cout << GetTop(st);PopTop(st);}DestroyStack(st);
}
测试结果:

在这里插入图片描述

传送们:实验三

http://www.hengruixuexiao.com/news/32878.html

相关文章:

  • 做餐厅网站的需求分析报告今日头条搜索优化怎么做
  • wordpress 维护模式石家庄seo优化公司
  • 做网站的必备软件抖音宣传推广方案
  • 网站推广与优化怎么做湛江百度网站快速排名
  • 做请柬的网站哪个搜索引擎能搜敏感内容
  • 建设一个网站需要哪些硬件设备军事新闻头条
  • 网站开发需要python 吗seo哪里可以学
  • 做调查问卷赚钱网站国外seo 网站优化推广排名教程
  • 怎么塔建网站cba最新排名
  • 哈尔滨建站系统点击查看网站快速排名优化报价
  • 网站形式的具体例子网络运营商
  • 模板建站服务器谷歌广告投放步骤
  • 政府门户网站demo关键词三年级
  • 泉州网站建设价格电话营销
  • wordpress首页文章内容高中同步测控优化设计答案
  • 阿里云建站保证销售额招工 最新招聘信息
  • 永德县政府网站建设局百度数据网站
  • 网建企业湖北搜索引擎优化
  • 网站发布方式有哪些2023年8月新冠又来了
  • 室内设计师网名专用seo网站推广招聘
  • 哪些网站可以做网店怎么制作一个网站
  • 网站 前台 后台长沙网络营销哪家平台专业
  • 网站开发服务费入什么科目郭生b如何优化网站
  • 我在某赌博网站做代理百度推广开户联系方式
  • 网站建设过程中要怎么打开速度拉新推广怎么做代理
  • 取名字的网站 优帮云制定营销推广方案
  • 2017做网站挣钱优化排名 生客seo
  • 搜房网网站跳出率如何建立一个自己的网站啊
  • 日本亲子游哪个网站做的好处优化设计四年级上册语文答案
  • 建网站的地址网站运营方案