Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn Phí
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Diễn đàn hỏi đáp học thuật - Download Tài Liệu Miễn PhíĐăng Nhập

VỮNG TIN - TIẾP BƯỚC - THÀNH CÔNG


descriptionThầy ơi sửa giúp em bài này! EmptyThầy ơi sửa giúp em bài này!

more_horiz

Code:


#include<conio.h>
#include<stdio.h>
#include<alloc.h>
#define FileIn "Graph.inp"

typedef int ElementType;
 typedef struct Node{
  ElementType Element;
  Node*Next;
};
typedef Node*Stack;
//Tao stack rong
Node*Make_Node(ElementType x){
 Node*temp=(Node*)malloc(sizeof(Node));
 temp->Element =x;
 return temp;
}
//khoi tao 1 Node
Stack MakeNull_Stack(){
 Stack temp=(Stack)malloc(sizeof(Stack));
 temp->Next=NULL;
 return temp;
}
//kiem tra stack rong
char Empty_Stack(Stack S){
 return S->Next==NULL;
}
//them pt vao ngan xep
void Push(Stack S,ElementType x){
 Node*P=Make_Node(x);
 P->Next=S->Next;
 S->Next=P;
}
//xoa pt ra khoi ngan xep
void Pop(Stack S){
 if(!Empty_Stack(S)){
 Node*temp=S->Next;
 S->Next=temp->Next;
 free(temp);
    }
}
//xuat phan tu ra khoi ngan xep
void Out_Stack(Stack L){
 Stack temp=L;
 while(!Empty_Stack(temp)){
  printf("%d\t",temp->Element);
  temp=temp->Next;
    }
}
//doc file
void Read_File( char **A, unsigned int &n, unsigned int &Start)
{
   FILE *f= fopen(FileIn,"rb");
   fscanf(f,"%d",&n,&Start);
   printf("This Matrix \n%d \n ",Start);
   *A=(char*)malloc(sizeof(char)*n);
   for(int i=0;i<n;i++)
   {
   A[i]=(char*)malloc(sizeof(char)*n);
   for(int j=0; j<n;j++)
   fscanf(f,"%d",&A[i][j]);
   printf("%d",A[i][j]);
   }
   printf("\n");
   Start-- ;
   fclose(f);
}
//ham tiem kiem duong di Hamilton
void Hamilton(char **A, unsigned int n, unsigned int Start){

   Stack S= MakeNull_Stack();
   Stack L= MakeNull_Stack();
   unsigned int Count = 0;
   char F=0;

   char *M = new char[n];
   Push(S,Start);
   for(int i=0;i<n;i++)
      M[i]=0;
   while(!Empty_Stack(S)){
   if(!Empty_Stack(S)){
   Start=Top(S);
   Push(L,Start);
   M[Start]=1;
   Count++;
}
   if(Count<n)
   {
   F=0;
   for(i=0;i<n;i++)
   if(A[Start][i]==1&&M[i]==0)
      {
   Push(S,i);
   F=i;
   }
}
   if(Count ==n||F==1)
      if(Count==n){
      printf("\n");
      Out_Stack(L);
}
while(!Empty_Stack(S) && Top(S)==Top(L)){
   M[Top(S)]=0;
   Pop(S);
   Pop(L);
   Count--;
   }
   }
   }

Stack Input_Stack(unsigned int n){
 Stack temp=MakeNull_Stack();
 unsigned int i=0;
 ElementType x;
 while(i<n)
      {
 printf("Element %d=",i);
 scanf("%d",&x);
 Push(temp,x);
 i++;
      }
      return temp;
}

void main(){
 clrscr();
   char **A;
 unsigned int n,Start;
   Read_File(A,n,Start);
   printf("Result!");
   Hamilton(A,n,Start);

    getch();
}

Bài này báo lỗi ở hàm Top (Function 'Top' should have a prototype) mà em không biết cách sửa. Thầy xem giúp em.

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz
Thì thêm hàm Top vào!

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz
Thầy thêm vào giùm em đi ạ.!E không biết thêm vào chổ nào cho đúng!

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz
duongvandeoit1k10 đã viết:
Thầy thêm vào giùm em đi ạ.!E không biết thêm vào chổ nào cho đúng!

Ngôn ngữ lập trình cơ bản, thêm vào trước lời gọi hàm. Lỗi này mà không biết sửa thì kể như ngôn ngữ lập trình tiêu rùi. Những lỗi về ngôn ngữ thì thầy sẽ không hướng dẫn cho em.

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz

Code:


#include<conio.h>
#include<stdio.h>
#include<alloc.h>
#define FileIn "Graph.inp"

typedef int ElementType;
 typedef struct Node{
  ElementType Element;
  Node*Next;
};
typedef Node*Stack;
//Tao stack rong
Node*Make_Node(ElementType x){

 Node*temp=(Node*)malloc(sizeof(Node));
 temp->Element =x;
return temp;
}
//khoi tao 1 Node
Stack MakeNull_Stack(){
 Stack temp=(Stack)malloc(sizeof(Stack));
 temp->Next=NULL;
 return temp;
}
//kiem tra stack rong
char Empty_Stack(Stack S){
 return S->Next==NULL;
}
//them pt vao ngan xep
void Push(Stack S,ElementType x){
 Node*P=Make_Node(x);
 P->Next=S->Next;
 S->Next=P;
}
//xoa pt ra khoi ngan xep
void Pop(Stack S){
 if(!Empty_Stack(S)){
 Node*temp=S->Next;
 S->Next=temp->Next;
 free(temp);
    }
}
//xuat phan tu ra khoi ngan xep
void Out_Stack(Stack L){
 Stack temp=L;
 while(!Empty_Stack(temp)){
  printf("%d\t",temp->Element);
  temp=temp->Next;

    }
}
//ham top
ElementType Top(Stack S){
   return S->Next->Element;
   }
//doc file
void Read_File( char **A, unsigned int &n, unsigned int &Start)
{
   FILE *f= fopen(FileIn,"rb");
   fscanf(f,"%d",&n,&Start);
   printf("This Matrix \n%d \n ",Start);
   *A=(char*)malloc(sizeof(char)*n);
   for(int i=0;i<n;i++)
   {
   A[i]=(char*)malloc(sizeof(char)*n);
   for(int j=0; j<n;j++)
   fscanf(f,"%d",&A[i][j]);
   printf("%d",A[i][j]);
   }
   printf("\n");
   Start-- ;
   fclose(f);
}
//ham tiem kiem duong di Hamilton
void Hamilton(char **A, unsigned int n, unsigned int Start){

   Stack S= MakeNull_Stack();
   Stack L= MakeNull_Stack();
   unsigned int Count = 0;
   char F=0;

   char *M = new char[n];
   Push(S,Start);
   for(int i=0;i<n;i++)
      M[i]=0;
   while(!Empty_Stack(S)){
   if(!Empty_Stack(S)){
   Start=Top(S);
   Push(L,Start);
   M[Start]=1;
   Count++;
}
   if(Count<n)
   {
   F=0;
   for(i=0;i<n;i++)
   if(A[Start][i]==1&&M[i]==0)
      {
   Push(S,i);
   F=i;
   }
}
   if(Count ==n||F==1)
      if(Count==n){
      printf("\n");
      Out_Stack(L);
}
while(!Empty_Stack(S) && Top(S)==Top(L)){
   M[Top(S)]=0;
   Pop(S);
   Pop(L);
   Count--;
   }
   }
   }


void main(){
 clrscr();
   char **A;
 unsigned int n,Start;
   Read_File(A,n,Start);
   printf("Result!");
   Hamilton(A,n,Start);

    getch();
}


Em Sửa được rồi thầy ơi nhưng mà nó không trả về kết quả của đường đi tìm được. Nhưng mà đây là bài thầy cho tụi em code nhưng về gõ vào máy thì nó không chạy thầy ơi.

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz
if(Count<n)
{
F=0;
for(i=0;i<n;i++)
if(A[Start][i]==1&&M[i]==0)
{
Push(S,i);
F=1;
}


- Em xem doc file co thanh cong chua chua?

descriptionThầy ơi sửa giúp em bài này! EmptyRe: Thầy ơi sửa giúp em bài này!

more_horiz
privacy_tip Permissions in this forum:
Bạn không có quyền trả lời bài viết
power_settings_newLogin to reply