الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[مخالف]طلب

مغلق
بدأه yaya2012 في 29 نوفمبر 2011 · 4 رد · 656 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

ياريت لو سمحت حد يتكرم ويشرح البرنامج دة

يعنى يقولى كل داله بتعمل ايه

ويكتب الـــ algoritm بتاعها

دة البرنامج

#define MAXNUM 100

#define N 12

#include <stdio.h>

#include <stdlib.h>

typedef struct

{

int x;

int y;

int d;

}DataType;

struct SeqStack

{ DataType s[MAXNUM];

int t;

};

typedef struct SeqStack *PSeqStack;

PSeqStack pastack;

PSeqStack createEmptyStack_seq( void )

{ PSeqStack pastack;

pastack = (PSeqStack)malloc(sizeof(struct SeqStack));

if (pastack==NULL)

printf("Out of space!! \n");

else

pastack->t=-1;

return (pastack);

}

int isEmptyStack_seq( PSeqStack pastack )

{

return ( pastack->t == -1 );

}

void push_seq( PSeqStack pastack, DataType x )

{ if( pastack->t >= MAXNUM - 1 )

printf( "Overflow! \n" );

else

{ pastack->t = pastack->t + 1;

pastack->s[pastack->t] = x;

}

}

void pop_seq( PSeqStack pastack )

{ if (pastack->t == -1 )

printf( "Underflow!\n" );

else

pastack->t = pastack->t - 1;

}

DataType top_seq( PSeqStack pastack )

{

return (pastack->s[pastack->t]);

}

void pushtostack(PSeqStack st, int x, int y, int d)

{ DataType element;

element.x = x;

element.y = y;

element.d = d;

push_seq(st,element);

}

void printpath(PSeqStack st)

{DataType element;

printf(" The revers path is:\n");

printf("--------------------------------------------------------------------------------\n");

while(!isEmptyStack_seq(st))

{ element=top_seq(st);

pop_seq(st);

printf("the node is: %d %d \n",element.x,element.y);

}

}

void mazePath(int maze[][N],int direction[][2],int x1,int y1,int x2,int y2)

{ int i,j,k,g,h;

PSeqStack st;

DataType element;

st = createEmptyStack_seq( );

maze[x1][y1] = 2;

pushtostack(st, x1, y1, -1);

while (! isEmptyStack_seq(st))

{ element = top_seq(st);

pop_seq(st);

i = element.x; j = element.y; k = element.d + 1;

while (k<=3)

{ g = i + direction[k][0];h = j + direction[k][1];

if (g==x2 && h==y2 && maze[g][h]==0)

{ printpath(st);

return;

}

if (maze[g][h]==0)

{ maze[g][h] = 2;

pushtostack(st, i, j, k);

i = g; j = h; k = -1;

}

k = k + 1;

}

}

printf("The path has not been found.\n");

}

int main(){

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

int maze[][N]={

1,1,1,1,1,1,1,1,1,1,1,1,

1,0,0,0,1,1,0,1,0,1,0,1,

1,1,1,0,1,0,0,0,0,0,0,1,

1,1,0,0,0,0,1,1,1,1,0,1,

1,1,0,1,1,1,1,1,1,1,0,0,

1,1,0,1,0,1,1,1,1,1,1,1,

1,1,0,0,0,1,1,1,1,1,1,1,

1,1,1,1,0,1,1,1,0,1,0,1,

1,1,0,0,0,0,0,1,0,0,0,1,

1,1,1,1,1,1,1,1,1,1,1,1,

1,1,1,1,1,1,1,1,1,1,1,1,

1,1,1,1,1,1,1,1,1,1,1,1

};

printf("--------------------------------------------------------------------------------\n");

printf(" the maze is\n");

printf("--------------------------------------------------------------------------------\n");

for(int i=0;i<=(N-1);i++)

{

for(int j=0;j<=(N-1);j++)

{

if(maze[j]==1)

{

printf("#");

}

else

{printf(".");}

}

printf("\n");

}

printf("--------------------------------------------------------------------------------\n");

printf("--------------------------------------------------------------------------------\n");

mazePath(maze,direction,8,2,4,11);

return 0;

}

تم تعديل هذه المشاركة بواسطة yaya2012 في 29 نوفمبر 2011 في 12:17

−1
#2
#define MAXNUM 100
#define N 12
#include <stdio.h>
#include <stdlib.h>

typedef struct

{

int x;

int y;

int d;

}DataType;

struct SeqStack
{ DataType s[MAXNUM];
int t;
};
typedef struct SeqStack *PSeqStack;
PSeqStack pastack;


PSeqStack createEmptyStack_seq( void )
{ PSeqStack pastack;
pastack = (PSeqStack)malloc(sizeof(struct SeqStack));
if (pastack==NULL)
printf("Out of space!! \n");
else
pastack->t=-1;
return (pastack);
}


int isEmptyStack_seq( PSeqStack pastack )
{
return ( pastack->t == -1 );
}


void push_seq( PSeqStack pastack, DataType x )

{ if( pastack->t >= MAXNUM - 1 )
printf( "Overflow! \n" );
else
{ pastack->t = pastack->t + 1;
pastack->s[pastack->t] = x;
}
}


void pop_seq( PSeqStack pastack )

{ if (pastack->t == -1 )
printf( "Underflow!\n" );
else
pastack->t = pastack->t - 1;
}


DataType top_seq( PSeqStack pastack )

{
return (pastack->s[pastack->t]);
}



void pushtostack(PSeqStack st, int x, int y, int d)

{ DataType element;

element.x = x;

element.y = y;

element.d = d;

push_seq(st,element);

}



void printpath(PSeqStack st)

{DataType element;
printf(" The revers path is:\n");
printf("--------------------------------------------------------------------------------\n");

while(!isEmptyStack_seq(st))

{ element=top_seq(st);

pop_seq(st);

printf("the node is: %d %d \n",element.x,element.y);

}

}




void mazePath(int maze[][N],int direction[][2],int x1,int y1,int x2,int y2)


{ int i,j,k,g,h;

PSeqStack st;

DataType element;

st = createEmptyStack_seq( );

maze[x1][y1] = 2;

pushtostack(st, x1, y1, -1);

while (! isEmptyStack_seq(st))

{ element = top_seq(st);

pop_seq(st);

i = element.x; j = element.y; k = element.d + 1;

while (k<=3)

{ g = i + direction[k][0];h = j + direction[k][1];

if (g==x2 && h==y2 && maze[g][h]==0)

{ printpath(st);

return;

}

if (maze[g][h]==0)

{ maze[g][h] = 2;

pushtostack(st, i, j, k);

i = g; j = h; k = -1;

}

k = k + 1;

}

}

printf("The path has not been found.\n");

}

int main(){
int direction[][2]={0,1,1,0,0,-1,-1,0};
int maze[][N]={
1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,1,1,0,1,0,1,0,1,
1,1,1,0,1,0,0,0,0,0,0,1,
1,1,0,0,0,0,1,1,1,1,0,1,
1,1,0,1,1,1,1,1,1,1,0,0,
1,1,0,1,0,1,1,1,1,1,1,1,
1,1,0,0,0,1,1,1,1,1,1,1,
1,1,1,1,0,1,1,1,0,1,0,1,
1,1,0,0,0,0,0,1,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1
};
printf("--------------------------------------------------------------------------------\n");
printf(" the maze is\n");
printf("--------------------------------------------------------------------------------\n");
for(int i=0;i<=(N-1);i++)
{
for(int j=0;j<=(N-1);j++)
{
if(maze[j]==1)
{
printf("#");
}
else
{printf(".");}

}
printf("\n");
}
printf("--------------------------------------------------------------------------------\n");
printf("--------------------------------------------------------------------------------\n");
mazePath(maze,direction,8,2,4,11);
return 0;
}

post-15367-027053900%201340345097.gifpost-15367-087183200%201340344597.gif
post-247365-0-10080400-1379403554_thumb.

#3

شكرا استاذ محمد

#4

ارجو سرعة الرد بعد اذنكم

#5

الأخ الكريم/الأخت الكريمة

السلام عليكم ورحمة الله وبركاته

مرحباً بكم في منتدى الفريق العربي للبرمجة

تأسف إدارة المنتدى لغلق الموضوع وذلك لمخالفته قوانين المشاركات .

قواعد طرح المشاركات

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

{username}

صورة
صورة

حسابي في الفيس بوك
http://goo.gl/XIzwL

حسابي في تويتر
http://goo.gl/6p4e3

 

 
 

هذا الموضوع مغلق.

مواضيع مشابهة