yigin.cpp
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<stdlib.h>
#include"yigin.h"
using namespace std;
void Yigin::olustur(){
bas==NULL;
}
void Yigin::kapat(){
stackPtr p;
while(bas){
p=bas;
bas=bas->sonraki;
delete p;
}
}
void Yigin::ekle(ogrenciPtr sPtr){
stackPtr yeni;
yeni = new Stack;
yeni->dugum = sPtr;
yeni->sonraki=bas;
bas=yeni;
}
ogrenciPtr Yigin::cikar(){
stackPtr ustdugum;
ogrenciPtr node;
node = new Ogrenci;
ustdugum = bas;
bas = bas->sonraki;
node = ustdugum->dugum;
delete ustdugum;
return node;
}
bool Yigin::bosmu(){
return bas==NULL;
}
void Yigin::ilkderinlikara(ogrenciPtr root,char *aranacak){
ogrenciPtr tara;
ekle(root);
while(!bosmu()){
tara = cikar();
if(tara->ogrno==aranacak){
cout << tara->ogrno <<" "<< tara->ad<<" "<<tara->soyad <<endl;
break;
}
if(tara->sagPtr!=NULL)
ekle(tara->sagPtr);
if(tara->solPtr!=NULL)
ekle(tara->solPtr);
}
if(bosmu())
cout << "Bu numarada bir ogrenci bulunamadi!"<<endl;
}
yigin.h
#ifndef YIGIN_H
#include<stdio.h>
#include"ogrenci.h"
struct stack{
ogrenciPtr dugum;
stack *sonraki;
};
typedef stack Stack;
typedef Stack *stackPtr;
struct Yigin{
stackPtr bas;
void olustur();
void ekle(ogrenciPtr);
ogrenciPtr cikar();
void ilkderinlikara(ogrenciPtr,char *);
bool bosmu();
void kapat();
};
#endif
No comments:
Post a Comment