澳门皇冠金沙网站-澳门皇冠844网站

热门关键词: 澳门皇冠金沙网站,澳门皇冠844网站

万分感谢,map实例讲解

c map 嵌套队列指针,队列嵌套结构体指针实例讲解,map实例讲解

#include

#include

#include

#include

#include

//#include

usingnamespacestd;

queue queue1;

/*queue* queue2;*/

//queue2 = (queue*)malloc(sizeof(queue));

for(inti = 0; i < 10; i ) {

RevDatarecvD;

recvD.size = i;

strcpy(recvD.data, "hello");

RevData* recvp = (RevData*)malloc(sizeof(RevData));

memcpy(recvp, &recvD, sizeof(RevData));

queue1.push(recvp);// recvp);

//queue1.push(&recvD);

}

map*> imap;

map*>* queue2;

//queue2 = (queue*)malloc(sizeof(queue));

for(inti = 0; i < 1; i ) {

imap[i]= &queue1;// recvp);

//imap[i]=&recvD;

}

queue2 = &imap;

for(inti = 0; i < 1; i ) {

queue* recv = (*queue2)[i];

for(intj = 0; j < 10; j ) {

RevData* recvd = recv->front();

cout <

cout <

intlenga = recv->size();

recv->pop();

}

}

map 嵌套队列指针,队列嵌套结构体指针实例讲解,map实例讲解 #include #include #include #include #include //#include usingnamespacestd; queue queue1; /*qu...

#define int Status
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define MAXSIZE 100

void bfs(bu s,char c)

typedef int Status;

 que.push(x1,y1);

//词汇依次出栈进行处理
//A情况
char Language_explanA(LinkStack S, LinkQueue Q) {
//char *e;
char *e = malloc(sizeof;
pop;
char E = *e;
free;
int a = 0;
char A[10] = "sae";
while (a <= 2) {
EnQueue;
a ;
}
return *e;
/*cout << A;
cout << "输出第一个元素";
cout << Q->front->data;/
//return OK;
}
//B情况
Status Language_explanB(LinkStack
S, LinkQueue *Q) {
//char *e;
char *e = (char)malloc(sizeof;
pop;
int b = 0;
char B[10] = "tsaedsae";
while {
EnQueue;
b ;
}
return 0;
}
//‘(’情况
Status Language_explanleft(LinkStack
S, LinkQueue *Q) {
//char *e;
char *e = (char)malloc(sizeof;
pop;
pop;
char sita =
e;
EnQueue;
while (S->top->data != ')') {
pop;
EnQueue;
EnQueue;
}
return 0;
}
//')'情况
Status Language_explanright(LinkStack *S, LinkQueue *Q) {
//char *e;
char *e = (char*)malloc(sizeof;
pop;
while (!QueueEmpty) {
DeQueue;
push;
}
return OK;
}

{  bfs(b[tmp[i-1]],'A' i);

cout << "成功输入魔王语言";while  { if (word[j] == ' left  ; if (word[j] == ')') right  ; j  ;}if  { cout << "魔王没有说话"; return ERROR;}else { if (left != right) { cout << "魔王说了错误的话"; return ERROR; } else { for (i = len;i >= 0;i--) { push(S, word[i]); } } }return OK;}

{ if(i<0||i>=n||j<0||j>=m||map[i][j]=='#||v[i][j]==1)  //越界或搜索过退出

//重要操作 LinkQueue
//判断是否为空队列
Status QueueEmpty(LinkQueue *Q) {
if (Q->Size == 0) {
return TRUE;
}
else {
return FALSE;
}
}
//初始化
Status InitQueue(LinkQueue *Q) {
Q->front = Q->rear = malloc(sizeof;
if (!Q->front) exit;
Q->front->next = NULL;
Q->Size = 0;
return OK;
}
//入队列
Status EnQueue(LinkQueue *Q, char e) {//链队列是带头节点的,头指针永远指向头节点
QueuePtr q = malloc(sizeof;
if exit;
q->data = e;
q->next = NULL;
Q->rear->next = q;
Q->rear = q;
Q->Size ;
return OK;
}
//出队列
Status DeQueue(LinkQueue *Q, char *e) {
if (Q->front == Q->rear) return ERROR;
*e = Q->front->data;
QueuePtr q = Q->front->next;
Q->front->next = q->next;
if (q == Q->rear) Q->rear = Q->front;
Q->Size--;
free;
return OK;
}

#include <algorithm>

}

   next.c=map[next.x][next.y];

//链栈
typedef struct StackNode {
char data;
struct StackNode *next;
}StackNode, *LinkStackPtr;
typedef struct LinkStack {
LinkStackPtr top;
int size;
}LinkStack;

int cha(bus,char c)

//重要操作 LinkStack
//判断是否为空栈
Status StackEmpty(LinkStack *S) {
if (S->size == 0) {
return TRUE;
}
else {
return FALSE;
}
}
//初始化一个栈
Status InitStack(LinkStack *S) {
S->top = NULL;
S->size = 0;
return OK;
}
//返回栈顶元素
Status GetTop(LinkStack *S, char * e) {//char
if (S->size == 0) {
return ERROR;
}
else {
*e = S->top->data;
}
皇冠体育365,return OK;
}
//进栈操作
Status push(LinkStack *S, char e) {
LinkStackPtr s = (LinkStackPtr)malloc(sizeof(StackNode));
s->data = e;
s->next = S->top;
S->top = s;
S->size ;
return OK;
}
//出栈操作
Status pop(LinkStack *S, char *e) {
if (StackEmpty {
return FALSE;
}
else {
*e = S->top->data;
LinkStackPtr s = S->top;
S->top = s->next;
S->size--;
free;
return OK;
}
}

       res =now.cout;

Language_Talk(Link_Stack);cout << Link_Stack->size;cout << Link_Stack->top->data << endl;while (!StackEmpty(Link_Stack)) { if (Link_Stack->top->data == 'A') { Language_explanA(Link_Stack, Link_Queue); cout << "执行了A"; cout << Link_Queue->Size << endl; cout << Link_Stack->size << endl; } if (Link_Stack->top->data == 'B') { Language_explanB(Link_Stack, Link_Queue); cout << Link_Queue->Size << endl; cout << Link_Stack->size << endl; } if (Link_Stack->top->data == ' { Language_Record(Link_Queue, Humanwords); Language_explanleft(Link_Stack, Link_Queue); } if (Link_Stack->top->data == ')') Language_explanright(Link_Stack, Link_Queue);}cout << Humanwords;system;return OK;

for(int ii=1;ii<=t;ii )

有大神帮忙看一下这个代码存在什么问题吗?万分感谢! 5C
一个数据结构的问题,在主函数中的‘B’情况运行到EnQueue的时候出现异常。
using namespace std;
#include
#include
#include
#include

queue <bu>q;

//已经解析的语言存入数组
Status Language_Record(LinkQueue *Q, LinkQueue *Q1) {
//char *e=;
char *e = malloc(sizeof;
while (!QueueEmpty {
DeQueue;
EnQueue;
}
return OK;
}

   res=0;

int main() {
int position = 0;
LinkStack *Link_Stack = (LinkStack *)malloc(sizeof(StackNode));
LinkQueue *Link_Queue = (LinkQueue *)malloc(sizeof;
LinkQueue *Humanwords = (LinkQueue *)malloc(sizeof;
InitStack(Link_Stack);
InitQueue(Link_Queue);
char Devilwords[MAXSIZE];

#include<iostream>

//链队列
typedef struct QNode {
char data;
struct QNode *next;
}QNode, *QueuePtr;//结点结构
typedef struct {
QueuePtr front, rear;
int Size;
}LinkQueue;//队列的链表结构

retun 1;

//talk函数用于将魔王的语言进行压栈
Status Language_Talk(LinkStack *S) {
char word[MAXSIZE];
cout << "请输入魔王的语言";
cin >> word;
int i;
int j = 0;
int left = 0, right = 0;
cout << "魔王语言为"<<word << endl;
int len = strlen - 1;
cout <<"魔王语言长度为"<< len 1 << endl;

bu now,next;

}   

      q.pop();

练习题d就是最短路了:

 vis[x1][y1]=1;

#include<string>

     if(now.c==c)

  }

    next.cout=now.cout 1;

if(q==n*m)  走这么多步后停止

上面的其实就是广搜,也叫宽搜,使用递归方式,然而有时候数据量过大时有可能会栈溢出,因此,正宗的广搜使用递推写的,队列加数组,其实原理就是把需要搜索的四个方向的点都加入队列中,然后循环条件为队列非空,再加个标记数组判重就好了。

l ;

}

    {     que.push(ti,tj);

}

     for(int i=0;i<4;i )

{  if(vis[s.x][s.y]==0&&s.x>=0&&s.x<n&&s.y>=0&&s.y<n&&(s.c=='.'||(s.c<=c&&s.c>='A'&&s.c<='Z')))

{   vis[i][j]=1;

int ii=i,jj=j;

求最短路的话,就是再加一个结构体数组存放原图,坐标和步数,然后点a向四个方向扩散时步数都是加1,这样就是最短路了。

  scanf("%d",&t);

    if(ti>=1&&ti<=n&&tj>=1&&tj<=m&&map[ti][tj]=='*'&&!vis[ti][tj])

using namespace std;

char map[21][21];

 {  int ti=movex[i] tmp.x,tj=movey[i] tmp.y;

#include<iostream>

}    

int dir[4][2]={0,1,0,-1,1,0,-1,0};

{    memset(vis,0,sizeof(vis));

vis[i][j]=0;    走不通的话,程序就运行到这里,标记数组还原为0

q.push(s);

待续……

int n,m;

#include <cstdio>

本文由澳门皇冠金沙网站发布于编辑程序,转载请注明出处:万分感谢,map实例讲解