Commit c5148af1 authored by cdf009's avatar cdf009

Lab5

parent 9699a4b4
#
# Copyright (c) 2012 Bucknell University
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: L. Felipe Perrone (perrone@bucknell.edu)
#
CC = gcc -I ./include
CFLAGS = -std=gnu99 -Wall -g #-DDEBUG
INC = ./include
SRC = ./src
OBJ = ./obj
DOC = ./doc
BIN = ./bin
vpath %.h ./include
vpath %.c ./src
EXECS = prodcons circular-list.o adt-test
all: mkpaths $(EXECS)
mkpaths:
mkdir -p $(OBJ)
doc:
doxygen
$(OBJ)/circular-list.o: $(INC)/circular-list.h $(SRC)/circular-list.c
$(CC) $(CFLAGS) -c $(SRC)/circular-list.c -o $(OBJ)/circular-list.o
$(BIN)/adt-test: $(SRC)/adt-test.c $(OBJ)/circular-list.o
$(CC) $(CFLAGS) $(SRC)/adt-test.c $(OBJ)/circular-list.o -o $(BIN)/adt-test
prodcons: $(OBJ)/circular-list.o
$(CC) $(CFLAGS) $(SRC)/prodcons.c $(OBJ)/circular-list.o -o $(BIN)/prodcons -lpthread
.PHONY: clean
clean:
/bin/rm -rf $(OBJ) $(EXECS) core* *~ ./src/*~ ./obj/* ./doc
#include "circular-list.c"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void){
struct circular_list l;
circular_list_create(&l, 10);
//double *v;
//v = (double*)(malloc(sizeof(double)));
circular_list_insert(&l,1);
//printf("%f", &l);
circular_list_insert(&l,2);
//printf("%f", &l);
circular_list_insert(&l,3);
//printf("%f", &l);
circular_list_insert(&l,4);
//printf("%f", &l);
circular_list_insert(&l,5);
//printf("%f", &l);
circular_list_insert(&l,6);
printf("ENTERING LOOP");
int j;
for(j=0; j<l.elems; j++){
printf("%f\n", l.buffer[j]);
}
double *v;
v = (double*)(malloc(sizeof(double)));
circular_list_remove(&l, v);
printf("%f", *v);
// call multiple inserts
// c
// insert 1
// insert 2
// insert 3
// insert 4
// insert 5
// insert 6
// deleting(&l, &v)
// printf("%d")
// delete
}
/*
* Copyright (c) 2013 Bucknell University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: L. Felipe Perrone (perrone@bucknell.edu)
*/
#include <stdlib.h>
#include "circular-list.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int circular_list_create(struct circular_list *l, int size) {
l->buffer = calloc(size, sizeof(item));
l->start = 0;
l->end = 0;
l->elems = 0;
l->size = size;
return 0;
}
int circular_list_insert(struct circular_list *l, item i) {
if(l->elems == l->size ){ //
return -1;
}
else {
//int len = l->size;
l->buffer[l->end] = i;
//l->end += 1;
l->end = (l->end+1) % l->size;
l->elems += 1;
return 0;
}
}
int circular_list_remove(struct circular_list *l, item *i) {
if(l->end == 0){
printf("Empty List!!!");
return -1;
}
// else{
*i = l->buffer[l->start];
//l->start += 1;
l->start = (l->start+1) % l->size;
l->elems -= 1;
return 0;
//}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment