2008年12月18日 星期四

2008w15




開始動手做BCB專案計畫了




鏈結串列運用到堆疊 等功能




光是堆疊我快瘋了壓


第二章圖是我一開始所做的


想裡面的程式碼....


//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
struct node
{ int data;
struct node *next;
};
struct node *first;
void construct()
{ first = (node *) malloc (sizeof(node));
first->data = 10;
first->next = (node*) malloc (sizeof(node));
first->next->data = 20;
first->next->next = NULL;
}
struct node * newnode(int element)
{struct node *p;
p = (node *) malloc (sizeof(node));
p->data = element;
p->next = NULL;
return p;
}
//struct node *first;
struct node *last;
void print_list(struct node * first)
{ struct node *p = first;
AnsiString s = "";
while (p != NULL)
{ s += IntToStr(p->data)+"->";
p = p->next;
}
Form1->Memo1->Lines->Add(s+"X");
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
struct node *p;
int element;
element = StrToInt(Edit1->Text);
first = newnode(element);
print_list(first);
last = first;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
struct node *p;
int element;
element = StrToInt(Edit1->Text);
p = newnode(element);
last->next = p;
last = p;
print_list(first);
}
//---------------------------------------------------------------------------


這是大概的~

還要再修改


沒有留言:

張貼留言