NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <string.h>
#define MAX_ROW 10

typedef struct Liste{
int per_no,index;
char isim[20],soyisim[20];
struct Liste *onceki,*sonraki;
}Listeler;

typedef struct Tablo{
Listeler list[MAX_ROW];
}Table;

Table table;

void initialize(){ // ilk bos degerlerin atanmasi
int i;
for(i=0; i<MAX_ROW ;i++){
table.list[i].per_no=-1;
table.list[i].index=-1;
table.list[i].isim[0]='';
table.list[i].soyisim[0]='';
table.list[i].onceki=NULL;
table.list[i].sonraki=NULL;
}
}

int Hash(int no){
int hash_index;
hash_index=no % MAX_ROW;
return hash_index;
}

void Hash_Ekleme(){
int no;
char ad[20],soyad[20];
Listeler *liste,*temp;
FILE *dosya=fopen("Personeller.txt","r");
if(dosya==NULL){
printf("nDosya bulunamadi..");
exit(0);
}
else{
while(!feof(dosya)){
fscanf(dosya,"%d %s %s",&no,ad,soyad);
if(table.list[Hash(no)].index==-1){ //ilk kayit bos ise
table.list[Hash(no)].index=Hash(no);
printf("%d ",table.list[Hash(no)].index);
table.list[Hash(no)].per_no=no;
printf("%d ",table.list[Hash(no)].per_no);
strcpy(table.list[Hash(no)].isim,ad);
printf("%s ",table.list[Hash(no)].isim);
strcpy(table.list[Hash(no)].soyisim,soyad);
printf("%s n",table.list[Hash(no)].soyisim);
}
else{
liste=(Listeler *)malloc(sizeof(Listeler));
if(liste==NULL){
printf("nBellekte yeterli alan yok..");
exit(0);
}
else{
liste->index=Hash(no);
printf("%d ",liste->index);
liste->per_no=no;
printf("%d ",liste->per_no);
strcpy(liste->isim,ad);
printf("%s ",liste->isim);
strcpy(liste->soyisim,soyad);
printf("%s n",liste->soyisim);
liste->sonraki=NULL;
liste->onceki=NULL;
temp=&table.list[Hash(no)]; //dugumler uzerinde gezecek dugum
while(temp->per_no<liste->per_no){ //liste -> eklenecek dugum
temp=temp->sonraki;
}
if(temp->sonraki==NULL){ //eger kayit son elemana eklenecek ise
temp->sonraki=liste;
}
temp->sonraki=liste; //cift yonlu bagli listede araya eleman ekleme
liste->onceki=temp;
liste->sonraki=NULL;
}
}
}
}
}

void Hash_Listele(){
int i;
Listeler *liste;
for(i=0;i<MAX_ROW;i++){
if(table.list[i].index!=-1){ //kayit varsa
// printf("n%d %s %s",table.list[i].per_no,table.list[i].isim,table.list[i].soyisim);
printf("n%d %d %= %d",table.list[i].index,table.list[i].per_no,MAX_ROW);
liste=table.list[i].sonraki;
while(liste!=NULL){
// printf(" %d %s %s",table.list[i].sonraki->per_no,table.list[i].sonraki->isim,table.list[i].sonraki->soyisim);
printf("n%d %d %= %d ",table.list[i].sonraki->index,table.list[i].sonraki->per_no,MAX_ROW);
liste=liste->sonraki;
}
}
else{ //kayit yoksa
printf("nBulunamadi!");
}
}
}

void Hash_Arama(int no){
int adim=0,hash_index;
hash_index=Hash(no);
Listeler *liste;
adim++;
if(table.list[hash_index].per_no==no){
printf("n%d %s %sn",table.list[hash_index].per_no,table.list[hash_index].isim,table.list[hash_index].soyisim);
printf("%d adimda ulasildi.",adim);
}
else{
liste=table.list[hash_index].sonraki;
while(liste!=NULL){
adim++;
printf("n%d %s %sn",table.list[hash_index].per_no,table.list[hash_index].isim,table.list[hash_index].soyisim);
if(liste->per_no==no){
printf("%d %s %sn",table.list[hash_index].sonraki->per_no,table.list[hash_index].sonraki->isim,table.list[hash_index].sonraki->soyisim);
printf("%d adimda ulasildi.",adim);
liste=liste->sonraki;
}
}
printf("nKayit bulunamadi!");
}
}

void Hash_Silme(int no){
int hash_index;
hash_index=Hash(no);
Listeler *liste;
Listeler *head=&table.list[hash_index];
if(head->per_no==no){
Listeler *temp=head; //ilk dugumun kaybolmamasi icin gecici degisken
head=head->sonraki; //cift yonlu bagli listede bastan eleman silme
head->onceki=NULL;
free(temp);
}
else{
liste=table.list[hash_index].sonraki;
if(liste==NULL){ //kayit bulunamazsa
printf("nSilme islemi basarisiz!");
}
else{
while(liste->per_no!=no){
liste=liste->sonraki;
}
if(liste->sonraki==NULL){ //cift yonlu bagli listede sondan eleman silme.liste suan son dugumu isaret ediyor
Listeler *temp=liste;
liste->onceki->sonraki=NULL;
free(temp);
}
else{ //cift yonlu bagli listede aradan eleman silme
Listeler *temp=liste->onceki;
liste->sonraki=temp->sonraki;
liste->sonraki->onceki=liste->onceki;
free(temp);
}
}
}
}

int Adim_Sayisi(int no){
int adim=0;
Listeler *liste;
adim++;
if(table.list[Hash(no)].per_no==no){
return adim;
}
else{
liste=table.list[Hash(no)].sonraki;
while(liste!=NULL){
adim++;
if(liste->per_no==no){
return adim;
}
liste=liste->sonraki;
}
}
}

int Toplam_Kayit(){
int i,sayac=0;
Listeler *liste;
for(i=0;i<MAX_ROW;i++){
if(table.list[i].index!=-1){
sayac++;
liste=table.list[i].sonraki;
while(liste!=NULL){
sayac++;
liste=liste->sonraki;
}
}
}
return sayac;
}

int Toplam_Adim(){
int i,toplam=0;
Listeler *liste;
for(i=0;i<MAX_ROW;i++){
if(table.list[i].index!=-1){
toplam+=Adim_Sayisi(table.list[i].per_no);
liste=table.list[i].sonraki;
while(liste!=NULL){
toplam+=Adim_Sayisi(liste->per_no);
liste=liste->sonraki;
}
}
}
return toplam;
}

void Hash_Hesapla(){
printf("nOrtalama adim sayisi: %.1f",(float)Toplam_Adim()/Toplam_Kayit());
}

int main(){
char select;
int no,key;
initialize();
while(1){
printf("ne-Kayit ekleme");
printf("nl-Kayitlari listeleme");
printf("na-Kayit arama");
printf("ns-Kayit silme");
printf("nh-Ortalama adim sayisi hesapla");
printf("nc-Cikis");
printf("nSeciminiz: ");
scanf("%c",&select);
switch(select){
case 'e':
Hash_Ekleme();
break;
case 'l':
Hash_Listele();
break;
case 'a':
printf("nAramak istediginiz personelin numarasini giriniz: ");
scanf("%d",&no);
Hash_Arama(no);
break;
case 's':
printf("nSilmek istediginiz personelin numarasini giriniz: ");
scanf("%d",&key);
Hash_Silme(key);
Hash_Listele();
break;
case 'h':
Hash_Hesapla();
break;
case 'c':
printf("nCikis yaptiniz..");
exit(0);
default:
printf("nYanlis secim..");
break;
}
}
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.