#include <stdlib.h>
#include <string.h>
/////////////////////////////////////////////////////////////////////////struct declar
typedef struct
{
int key;
}list;
typedef struct node *node_pointer;
typedef struct node{
struct node *llink;
list item;
struct node *rlink;
} node;
///////////////////////////////////////////////////////////////////////////Global Variable
int a[100000000];
int buffer[100000000];
char b[8];
int count;
int result_s;
////////////////////////////////////////////////////////////////////////Reading dblab_lru.txt
void readingfile(){
FILE *fp;
// char temp;
printf("Reading dblab_lru.txt file... \n");
fp = fopen("dblab_lru.txt", "r");
count=0;
while( !feof(fp) )
{
fscanf(fp,"%d",&a[count]);
count++;
}
fclose(fp);
printf("Reading Complete \n");
}
///////////////////////////////////////////////////////////////////////Node Insert
void dinsert(node_pointer node, node_pointer newnode)
{
newnode ->llink = node;
newnode ->rlink = node ->rlink;
node ->rlink ->llink = newnode;
node ->rlink = newnode;
}
/////////////////////////////////////////////////////////////////////////Node Delete
void ddelete(node_pointer node, node_pointer deleted)
{
if(node == deleted)
{
printf("Deletion of head node not permitted. \n");
}
else
{
deleted ->llink ->rlink = deleted ->rlink;
deleted ->rlink ->llink = deleted ->llink;
free(deleted);
}
}
/////////////////////////////////////////////////////////////////////////Node Print
void Print(node_pointer ptr) {
node_pointer ptr2;
ptr2 = ptr->rlink;
for(ptr2; ptr2 != ptr; ptr2=ptr2->rlink)
printf("%d\n", ptr2->item.key);
}
//////////////////////////////////////////////////////////////////////////Search Function
/*
int search(node_pointer ptr, int next_i){
{
node_pointer ptr3;
ptr3=ptr->rlink;
while(ptr3->item.key != next_i && ptr3 != NULL)
ptr3=ptr3->rlink;
return *ptr3;
}*/
//////////////////////////////////////////////////////////////////////////Main Function
int main(){
node_pointer ptr;
ptr = (node_pointer)malloc(sizeof(node));
ptr ->llink = ptr;
ptr ->rlink = ptr;
node_pointer newnode;
int si;
int imsi;
printf("Input Buffer Size [Size Limit : 7000] : ");
scanf("%d", &si);
printf("Buffer Size is %d !\n", si);
readingfile();
for(int c=0 ; c < si ;c++){
newnode = (node_pointer)malloc(sizeof(node));
imsi = (int)a[c];
newnode->item.key = imsi;
dinsert(ptr, newnode);
}
printf("In Buffer : %d\n",si);
printf("ITEM : ");
Print(ptr);
printf("\n");
// ddelete(ptr, ptr->rlink);
}