Revision: 36416
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 22, 2010 01:12 by mpiknjac
Initial Code
//implementacija reda pomocu polja
#define m 50
struct klijent{
char preime[50];
int god;
float st_r;
char vr_t;
};
struct red{
klijent polje[m];
int celo, zacelje;
};
red *InitQ(red *Q){
Q = new red;
Q->celo = 0;
Q->zacelje = m-1;
return Q;
}
int AddOne(int n) {
return (( n + 1 ) % m);
}
klijent FrontQ(red*Q){
return Q->polje[Q->celo];
}
void EnqueueQ(klijent x, red *Q){
Q->zacelje = AddOne(Q->zacelje);
Q->polje[Q->zacelje] = x;
}
void DequeueQ(red *Q){
Q->celo = AddOne(Q->celo);
}
bool IsEmptyQ(red *Q){
if(AddOne(Q->zacelje)==Q->celo)
return true;
else return false;
}
//------------------------------------------------------------
//implementacija reda pomocu pokazivaca
struct klijent{
char preime[50];
int god;
float st_r;
char vr_t;
};
struct el{
klijent elem;
el *sljedeci;
};
struct red{
el *celo, *zacelje;
};
typedef struct klijent element;
typedef struct red Queue;
red* InitQ(red *Q){
el *novi=new el;
Q = new red;
novi->sljedeci=NULL;
Q->zacelje=novi;
Q->celo=novi;
return Q;
}
klijent FrontQ(red *Q){
return Q->celo->sljedeci->elem;
}
void EnqueueQ(element x, red *Q){
el *novi=new el;
novi->elem = x;
novi->sljedeci=NULL;
Q->zacelje->sljedeci=novi;
Q->zacelje=novi;
}
void DequeueQ(red *Q){
el *brisi = Q->celo;
Q->celo = brisi->sljedeci;
delete brisi;
}
bool IsEmptyQ(red *Q){
if(Q->zacelje==Q->celo)
return true;
return false;
}
//---------------------------------------------------------------
//glavna datoteka programa
#include <iostream>
#include "red_polje.h"
//#include "red_pokazivac.h"
using namespace std;
klijent dodaj(klijent podaci){
cout<<"Prezime i ime: ";
cin.ignore();
cin.getline(podaci.preime, 50);
cout<<"Godina rodenja: ";
cin>> podaci.god;
cout<<"Stanje racuna: ";
cin>>podaci.st_r;
cout<<"Vrsta transakcije uplata(u) / isplata(i) / placanje racuna(p) / kredit(k): ";
cin>>podaci.vr_t;
return podaci;
}
void unos(red *Q){
klijent podaci=dodaj(podaci);
EnqueueQ(podaci,Q);
}
bool prednost(klijent podaci){
if(podaci.god<1945)
return true;
else
return false;
}
void stari(red *Q){
red *tempQ=InitQ(tempQ);
red *tempOldQ=InitQ(tempOldQ);
klijent temp;
while(!IsEmptyQ(Q)){
temp=FrontQ(Q);
if(prednost(temp))
EnqueueQ(temp,tempOldQ);
else
EnqueueQ(temp,tempQ);
DequeueQ(Q);
}
while(!IsEmptyQ(tempOldQ)){
temp=FrontQ(tempOldQ);
EnqueueQ(temp,Q);
DequeueQ(tempOldQ);
}
while(!IsEmptyQ(tempQ)){
temp=FrontQ(tempQ);
EnqueueQ(temp, Q);
DequeueQ(tempQ);
}
}
void ispis(red *Q){
if(IsEmptyQ(Q)){
cout<<"\n\nNema klijenata u redu!!!\n";
return;
}
cout<<"\nStanje u redu!\n";
red *tempQ=InitQ(tempQ);
klijent temp;
while(!IsEmptyQ(Q)){
temp=FrontQ(Q);
cout<<"\nPrezime i ime: "<<temp.preime<<endl;
cout<<"Godina rodjenja: "<<temp.god<<endl;
cout<<"Stanje na racunu: "<<temp.st_r<<endl;
cout<<"Vrsta transakcije: ";
if(temp.vr_t=='u') cout<<"uplata\n";
else if(temp.vr_t=='i') cout<<"isplata\n";
else if(temp.vr_t=='p') cout<<"placanje racuna\n";
else if(temp.vr_t=='k') cout<<"kredit\n";
cout<<endl;
EnqueueQ(temp,tempQ);
DequeueQ(Q);
}
while(!IsEmptyQ(tempQ)){
temp=FrontQ(tempQ);
EnqueueQ(temp,Q);
DequeueQ(tempQ);
}
}
bool kr_sp(klijent element){
if(element.st_r<100 && element.vr_t=='k')
return false;
else
return true;
}
void izbaci(red *Q){
if(IsEmptyQ(Q)){
cout<<"\n\nNema klijenata u redu!!!\n";
return;
}
int br=0;
red *tempQ=InitQ(tempQ);
klijent temp;
while(!IsEmptyQ(Q)){
temp=FrontQ(Q);
if(kr_sp(temp)) EnqueueQ(temp,tempQ);
DequeueQ(Q);
}
memcpy(Q,tempQ,sizeof(red));
cout<<"\nKreditno nesposobni su izbaceni iz reda!\n";
}
void novi_red(red *Q){
klijent temp=FrontQ(Q);
DequeueQ(Q);
if(!IsEmptyQ(Q))
novi_red(Q);
EnqueueQ(temp,Q);
}
int main(){
red *red_banka=InitQ(red_banka);
int izbor;;
do{
cout<<endl<<"\nIZBORNIK\n\n"<<endl;
cout<<"1. Novi zapis"<< endl;
cout<<"2. Ispis reda"<<endl;
cout<<"3. Brisanje kreditno nesposobnih"<<endl;
cout<<"4. Otvaranje novog saltera"<<endl;
cout<<"0. Izlaz"<<endl;
cout<<"--------------------------------"<<endl;
cout<<"Vas izbor: ";
cin>>izbor;
switch(izbor){
case 0:break;
case 1:
unos(red_banka);
stari(red_banka);
break;
case 2:
ispis(red_banka);
break;
case 3:
izbaci(red_banka);
break;
case 4:
novi_red(red_banka);
cout<<"\nZatvoren je jedan salter i otvoren novi.\nKlijenti se u njemu nalaze obrnutim radosljedom s obzirom na stari poredak!\n";
break;
default: cout<<"\nKrivi unos!!!\n";
}
}while(izbor!=0);
return 0;
}
Initial URL
Initial Description
Initial Title
3. zadatak iz kolegija "Strukture podataka$"
Initial Tags
podataka
Initial Language
C++