Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

請大家幫個忙........

0 views
Skip to first unread message

搞屁阿~悶

unread,
Dec 28, 2005, 12:59:16 PM12/28/05
to
#include<iostream>
const int max_length=50;
typedef double itemtype;

class list{
public:
solist();
bool isEmpty()const;
bool isFull()const;
int lenght()const;
void insert(itemtype item);
void Delete(itemtype item);
bool isPresent(itemtype item)const;
void print();
void BinSearch(itemtype item,bool& found,int& position)const;
private:
int length;
itemtype data[max_length];

};
//#include "list.h"
#include<fstream>
using namespace std;

void list::insert(itemtype item)
{
int index;
index=length-1;
while(index>=0 && item<data[index])
{
data[index+1]=data[index];
index--;
}
data[index]=item;
length++;
}


bool list::isEmpty()const
{
return(length==0);
}
void list::Delete(itemtype item)
{
bool found;
int position;
int index;
BinSearch(item,found,position);
if(found)
{
for(index=position;index<length+1;index++)
data[index]=data[index+1];
length--;
}

}
void list::BinSearch(itemtype item,bool & found,int & position)const
{
int middle;
int first=0;
int last=length-1;
found=false;
while(last>=first && !found)
{
middle=(first+last)/2;
if(item<data[middle])
last=middle-1;
else if(item>data[middle])
first=middle+1;
else
found=true;
}
if(found)
position=middle;
}
bool list::isPresent(itemtype item)const
{
bool found;
int position;
BinSearch(item,found,position);
return found;
}
void list::print(){
//BinSearch();
//isPresent();
int index;
cout<<" the data "<<endl;
//for(index=0;index<=2;index++)
//{cout<<"data "<<": "<<data[index];}
}

int main(){
list s,*d,*i,*p;
i=&s;
d=&s;
p=&s;
i->insert;
d->Delete(2.1);
p->print();
return 0;
}
--
位啥跑出來沒東西..
--
[1;32m※ Origin: [33m摩卡小築 [37m<moca.csie.chu.edu.tw> [m
[1;31m◆ From: [36mNAT2.Dorm.chu.edu.tw [m

0 new messages