10 Mart 2010 Çarşamba

C++ de Liste Kullanımı

//www.ethemsulan.com
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
#define max 10
/*Bu liste icin yazylmystır..*/
struct list{
       char diz[max];
       int count;
       };
typedef struct list liste;
void intialize(liste *ptr);
void insert(liste *ptr,char item);
void delet(liste *ptr,int pos);
bool isfull(liste *ptr);
bool isempty(liste *ptr);
int find(liste *ptr,char item);
void intialize(liste *ptr){
     ptr->count=0;
     }
bool isfull(liste *ptr){
     if(ptr->count==max)
     return true;
     else 
     return false;
     }
bool isempty(liste *ptr){
     if(ptr->count==0)
     return true;
     else 
     return false;
     }
void insert(liste *ptr,int item){
     int pos,current;
     if(isfull(ptr)){
                     fprintf(stderr,"list is full");
                     exit(1);
                     }
     for(pos=0;pos<ptr->count;pos++){
              if(ptr->diz[pos]>item)
              break;
                      }
     current=ptr->count-1;
     while(current>=pos){
         ptr->diz[current+1]=ptr->diz[current];
         current--;
                         }
         ptr->diz[pos]=item;
         ptr->count++;
     }
int main(int argc, char *argv[])
{
    liste a[10]={12,1,3,4,5,6,7,8,9,15};
    int k=5;
   insert(a,k);
  
  system("PAUSE");	
  return 0;
}

Hiç yorum yok:

Yorum Gönder