Chúc tất cả các bạn có một Trung Thu vui vẻ bên gia đình !!               Have fun !!
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.

Chúc tất cả các bạn có một Trung Thu vui vẻ bên gia đình !!               Have fun !!

Learning by doing
 
Trang ChínhLatest imagesTìm kiếmĐăng kýĐăng Nhập

 

 Please find some error in this program!!

Go down 
Tác giảThông điệp
ltbaogt




Tổng số bài gửi : 18
Join date : 01/01/2010

Please find some error in this program!! Empty
Bài gửiTiêu đề: Please find some error in this program!!   Please find some error in this program!! Icon_minitimeTue Apr 13, 2010 10:28 pm

Code:
#include<stdio.h>
#include <conio.h> // maybe there are some library needn't
#include <string.h>
#include <iostream.h>
struct node
{
   int x;
   node *pnext;
};
typedef node NODE;
node* TaoNode(int x)
{
   node* pnode=new node;
   if(pnode==NULL)
   {
      return NULL;
   }
   pnode->x=x;
   pnode->pnext=NULL;
   return pnode;
}
bool ThemDau(node* &phead,int data)
{
   node *pnode=TaoNode(data);
   if(phead==NULL)
   {
      phead=pnode;
      
   }
   pnode->pnext=phead;
   pnode->x=data;
   phead=pnode;
   return true;
   
}
node* XoaDau(node* &phead)
{
   node* pnode;
   if(phead==NULL)
   {
      printf("Danh Sach Rong");
   }
   else
   {
      pnode=phead;
      return pnode;
      phead=NULL;
   }
   return pnode;
   
}
node* XoaCuoi(node* phead)  // Where is error in this function ?
{                     // please check it for me and find some error !
   node* pdel;            //Notice: This function still runs normally but it shows to you a error table on the Dos Screen
   if(phead==NULL)
   {
      return NULL;
   }
   if(phead->pnext==NULL)
   {
      pdel=phead;
      return pdel;
      phead=NULL;
   }
   node* pcur;
   {
      pdel=phead;
      while(pdel->pnext->pnext!=NULL)
      {
         pdel=pdel->pnext;
      }
      pcur=pdel->pnext;
      pdel->pnext=NULL;

      return pcur;
      
   }
   
}
void main()
{
   int n;
   printf("Nhap so Node: ");
   scanf("%d",&n);
   node* pnode=NULL;
   for(int i=n;i>0;i--)
   {
      ThemDau(pnode,i);
      printf("%d\n",pnode->x);
      printf("%d\n",pnode->pnext);
   }
   printf("\n")
      ;   node* pdel=XoaDau(pnode);
   printf("Pop :");
   printf("%d\n",pdel->x);
   printf("%d\n",pdel->pnext);
   node *ptail=XoaCuoi(pnode);
   printf("%d\n",ptail->x);
   
   
   
}
Về Đầu Trang Go down
 
Please find some error in this program!!
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» Error.Repair.Professional.4.1.1.rar | 5Mb

Permissions in this forum:Bạn không có quyền trả lời bài viết
Chúc tất cả các bạn có một Trung Thu vui vẻ bên gia đình !!               Have fun !! :: Môn Học Cũ :: Bài Học: Cấu Trúc Dữ Liệu Và Giải Thuật :: Cấu Trúc Dữ Liệu Và Giải Thuật-
Chuyển đến