Today was the first day of class. It was a lot of first day kind of material, topics covered through the semester, books needed, etc. I'm looking forward to a class that is completely controlled by Matt. The class already seems like it will have more focus and structure to it than classes I have had in the past few semesters. I like the fact that we will need to have little meetings with Matt to go over what we learned and have done, I feel like that will be beneficial to our understanding of the material and ultimately will lead to better work done by everyone.
Today in data structures we began what is sure to be a long discussion about pointers. We started by creating a simple program, shown below, in which pointers are used.
#include <stdio.h> #include <stdlib.h> int main() { int a, *b; a=12; b=&a; fprintf(stdout, "[a] address is: 0x%X\n", &a); fprintf(stdout, "[a] contains: %d\n", a); //fprintf(stdout, "[a] dereferences to: %d\n", *a); fprintf(stdout, "[a] address is: 0x%X\n", &b); fprintf(stdout, "[a] contains: %d\n", b); fprintf(stdout, "[a] dereferences to: %d\n", *b); return(0); }
One important thing to take note of in this program are that “&a,” is equivalent to saying “the address of a”. When the program is run it shows the following.
[a] address is: 0xF0E7027C [a] contains: 12 [b] adress is 0xF0E70270 [b] contains: 0xF0E7027C [b] dereferences to: 12
Running the program we see that the variable b contains the address of a and dereferences to the value of a.
Next we explored the idea of how the program would be affected if the values of “a” and “*b” were changed.
#include <stdio.h> #include <stdlib.h> int main() { int a, *b; a=12; b=&a; fprintf(stdout, "[a] address is: 0x%X\n", &a); fprintf(stdout, "[a] contains: %d\n", a); //fprintf(stdout, "[a] dereferences to: %d\n", *a); fprintf(stdout, "[a] address is: 0x%X\n", &b); fprintf(stdout, "[a] contains: %d\n", b); fprintf(stdout, "[a] dereferences to: %d\n", *b); a=137; fprintf(stdout, "[a] address is: 0x%X\n", &a); fprintf(stdout, "[a] contains: %d\n", a); //fprintf(stdout, "[a] dereferences to: %d\n", *a); fprintf(stdout, "[a] address is: 0x%X\n", &b); fprintf(stdout, "[a] contains: %d\n", b); fprintf(stdout, "[a] dereferences to: %d\n", *b); *b=2600; fprintf(stdout, "[a] address is: 0x%X\n", &a); fprintf(stdout, "[a] contains: %d\n", a); //fprintf(stdout, "[a] dereferences to: %d\n", *a); fprintf(stdout, "[a] address is: 0x%X\n", &b); fprintf(stdout, "[a] contains: %d\n", b); fprintf(stdout, "[a] dereferences to: %d\n", *b); return(0); }
Running the program gives the following results
[a] address is: 0x8728A74C [a] contains: 12 [b] adress is 0x8728A740 [b] contains: 0x8728A74C [b] dereferences to: 12 [a] address is: 0x8728A74C [a] contains: 137 [b] adress is 0x8728A740 [b] contains: 0x8728A74C [b] dereferences to: 137 [a] address is: 0x8728A74C [a] contains: 2600 [b] adress is 0x8728A740 [b] contains: 0x8728A74C [b] dereferences to: 2600
We see how changing the value of “a” gives similar results to the first program. The interesting about these results is how when the value of “*b” is changed is also affects the value of “a”. This is because the when the value of “*b” is changed it changes the data that “b” “points” to, which would be that data located at the address of “a”, “&a”.
The topic of today was data types. By creating a program we checked the sizes of the data types int, char, float, double, and various unsigned/signed and long/short versions of those. The code below is for the signed and unsigned chars.
#include <stdio.h> #include <stdlib.h> int main() { signed char sc=0; unsigned char uc=0; signed short int ssi=0; unsigned short int usi=0; signed int si=0; unsigned int ui=0; signed long int sli=0; unsigned long int uli=0; signed long long int slli=0; unsigned long long int ulli=0; fprintf(stdout, "a signed char is %hhu bytes\n", sizeof(sc)); fprintf(stdout, "lower bound is: %hhd\n", ((unsigned char)(sc-1)/2)+1); fprintf(stdout, "upper bound is: %hhd\n", ((unsigned char)(sc-1)/2)); fprintf(stdout, "----------\n"); fprintf(stdout, "a unsigned char is %hhu bytes\n", sizeof(uc)); fprintf(stdout, "lower bound is: %hhu\n", uc); fprintf(stdout, "upper bound is: %hhu\n", uc-1); fprintf(stdout, "----------\n"); return(0); }
With the foolowing results when run
lab46:~/src/datastructures$ ./Dtypes a signed char is 1 bytes lower bound is: -128 upper bound is: 127 ---------- a unsigned char is 1 bytes lower bound is: 0 upper bound is: 255 ----------
We were given an assignment completing the assignment for the rest of the data types, and also to do some of the bounds using logical solutions. To do the logical solutions we were given the following syntax
The completed program can be found in the projects section of this opus.
Today in lecture we created a review program. In it we went over structs, arrays, for loops, and while loops.
It is important to remember that a “;” is needed at the end of a struct.
Whenever you allocate memory, it is important to free that memory once it is no longer needed to prevent memory leaks.
#include <stdio.h> #include <stdlib.h> int main() { struct person{ char *name; int age; long int id; }; typedef struct person Person; Person People[8]; int i=0; for(i=0; i<8; i++) { fprintf(stdout, "Enter person #%d's name: ", (i+1)); People[i].name=(char*)malloc(sizeof(char)*20); fscanf(stdin, "%s", People[i].name); fprintf(stdout, "Enter %'s age: ", People[i].name); fscanf(stdin, "%d", &People[i].age); fprintf(stdout, "Enter %s's id number: ", People[i].name); fscanf(stdin, "%ld", &People[i].id); } i=-1; while(i==-1) { fprintf(stdout, "Look up date for person #: "); fscanf(stdin, "%d", &i); if(!((i>=0)&&(i<=7))) { fprintf(stdout, "Invalid person #, Try Again!\n"); i=-1; } } i--; fprintf(stdout, "Name: %s\n", People[i].name); fprintf(stdout, "Age: %d\n", People[i].age); fprintf(stdout, "ID: %ld\n", People[i].id); return(0); }
These past two days we have been exploring the idea of link lists. We discussed the ideas of insertion, appending, and removal, having only worked with the first two. I see how this will be useful when I need to create the solitaire program, the appending seems especially useful for when I need to move cards from one stack to another. The code below is the code we created in class.
#include <stdio.h> #include <stdlib.h> struct node{ int value; struct node*next; }; typedef struct node Node; int main() { int input=0; Node*list, *tmp; list=tmp=NULL; while(input!=-1) { fprintf(stdout, "Enter a value (-1 to end): "); fscanf(stdin, "%d", &input); if(input!=-1) { if(list==NULL) { list=tmp=(Node*)malloc(sizeof(Node)); tmp->next=NULL; list->value=input; } else { tmp->next=(Node*)malloc(sizeof(Node)); tmp->next->next=NULL; tmp->next->value=input; tmp=tmp->next; } } } tmp=list; input=0; while(tmp!=NULL) { fprintf(stdout, "%d ->",tmp->value); tmp=tmp->next; input=input++; } fprintf(stdout, "NULL\n"); //insert into list fprintf(stdout, "Which node would you like to insert before? "); fscanf(stdin, "%d", &input); int seeker; tmp=list; Node*tmp2=NULL; for(seeker=0; seeker<(input-1); seeker++) { tmp=tmp->next; } fprintf(stdout, "Eneter a value to insert: "); fscanf(stdin, "%d", &input); tmp2=(Node*)malloc(sizeof(Node)); tmp2->value=input; tmp2->next=tmp->next; tmp->next=tmp2; return(0); }
After completing the insert for our linkedlist program, it became apparent that there was a problem with our current code. When we went to insert a node before the very first node it would put the node one behind it. To fix this we decided to add to our program rather than take away from it.
if(input==0) { fprintf(stdout, "Enter value for new node: "): fscanf(stdin, "%d", &input); tmp2=(Node*malloc(sizeof(Node)); tmp2->value=input; tmp2->next=NULL; tmp2->next=tmp; list=tmp2; }
We added the code above right after the for loop with the variable “seeker” and we also put the previous print out of the list into the “else”.
The best lesson of this day was the idea that when a problem occurs with code it is not necessarily the best approach to change or remove from what what you already have, and that adding to existing code is sometimes the best option. This will be good for future assignments and other programming exploits and wiull be sure to save some time here and there.
Yesterday was a very productive day, having completed both the append and remove functionality to the linkedlist program. The code for these can be found below.
The code for the append function is
fprintf(stdout, "Enter what node you would like to append to: "); fscanf(stdin, "%d", &input); int behind; tmp=list; Node*tmp3=NULL; for(behind=0; behind<input; behind++) { tmp=tmp->next; } fprintf(stdout, "What value would you like to append: "); fscanf(stdin, "%d", &input); tmp3=(Node*)malloc(sizeof(Node)); tmp3->value=input; tmp3->next=tmp->next; tmp->next=tmp3; tmp=list; input=0; while(tmp!=NULL) { fprintf(stdout, "[%d] %d -> ", input, tmp->value); tmp=tmp->next; input=input++; } fprintf(stdout, "NULL\n");
and the remove functionality code is
tmp=list; int remove; fprintf(stdout, "Which node would you like to remove?: "); fscanf(stdin, "%d", &input); for(remove=0; remove<(input-1);remove++) { tmp=tmp->next; } if(input==0) { tmp2=tmp->next; tmp->next=NULL; list=tmp2; } else { tmp2=tmp->next; tmp->next=tmp2->next; tmp2->next=NULL; } tmp=list; input=0; while(tmp!=NULL) { fprintf(stdout, "[%d] %d -> ", input, tmp->value); tmp=tmp->next; input=input++; } fprintf(stdout, "NULL\n");
Today in lecture we started working on the doubly linklist. Together we created the part of the program that builds the program,
#include <stdio.h> #include <stdlib.h> struct node { int value; struct node *next; struct node *prev; }; typedef struct node Node; struct list { struct node *start; struct node *end; }; List *build(); void displayf(List*); void displayb(List*); int main() { List *myList; myList=build(); displayf(myList); displayb(myList); return(0); } List *build() { Node *tmp=NULL; List *myList=(List*)malloc(sizeof(List)); myList->start=myList->end=NULL; int input = 0; fprintf(stdout, "Enter a value (-1 to quit): "); fscanf(stdin, "%d", &input); while(input !=-1) { if(myList->start==NULL) { myList->start=myList->end=(Node*)malloc(sizeof(Node)); myList->start->value=input; myList->end->prev=myList->start->next=NULL; } else { myList->end->next=(Node*)malloc(sizeof(Node)); myList->end->next->value=input; myList->end->next->next=NULL; myList->end->next->prev=myList->end; myList->end=myList->end->next; } fprintf(stdout, "Enter another value(-1 to quit): "); fscanf(stdin, "%d", &input); } return(myList); }
We were also asked to create a display forward function for our doubly linkedlist,
void displayf(List *myList) { Node *tmp=myList->start; int input=0; while(tmp !=NULL) { fprintf(stdout, "[%d] %d -> ", input, tmp->value); tmp=tmp->next; input=input++; } fprintf(stdout, "NULL\n"; }
Today we had a catch up day with everyone working on whatever they needed to. For me this meant taking all the parts of my linked list program, build, insert. append, remove, display, and putting them into separate functions of their own. This was completed with a slick menu that allows the user to choose which course they would like to take. The code for this can be found below.
#include <stdio.h> #include <stdlib.h> struct node{ int value; struct node*next; }; typedef struct node Node; Node *build(Node *); Node *insert(Node *); Node *append(Node *); Node *exile(Node *); Node *display(Node *); int main() { Node *list = NULL; int choice; while(choice!=-1) { fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 1 to build list |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 2 to insert to list |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 3 to append to list |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 4 to remove from list |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 5 to display the list |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| -1 to quit |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "Which would you like to do?\n"); fscanf(stdin, "%d", &choice); if(choice==1) { list=build(list); } else if(choice==2) { list=insert(list); } else if(choice==4) { list=exile(list); } else if(choice==5) { list=display(list); } else if(choice=-1) { fprintf(stdout, "Goodbye\n"); } else { fprintf(stdout, "Error, invalid input\n"); } } return(0); Node *build(Node*list) { int input=0; Node*tmp; list=tmp=NULL; while(input!=-1) { fprintf(stdout, "Enter a value (-1 to end): "); fscanf(stdin, "%d", &input); if(input!=-1) { if(list==NULL) { list=tmp=(Node*)malloc(sizeof(Node)); tmp->next=NULL; list->value=input; } else { tmp->next=(Node*)malloc(sizeof(Node)); tmp->next->next=NULL; tmp->next->value=input; tmp=tmp->next; } } } tmp=list; return(list); } Node *insert(Node*list) { //insert into list int input=0; Node*tmp; fprintf(stdout, "Which node would you like to insert before? "); fscanf(stdin, "%d", &input); int seeker; tmp=list; Node*tmp2=NULL; for(seeker=0; seeker<(input-1); seeker++) { tmp=tmp->next; } if(input==0) { fprintf(stdout, "Enter value for new node: "); fscanf(stdin, "%d", &input); tmp2=(Node*)malloc(sizeof(Node)); tmp2->value=input; tmp2->next=NULL; tmp2->next=tmp; list=tmp2; } else { fprintf(stdout, "Enter a value to insert: "); fscanf(stdin, "%d", &input); tmp2=(Node*)malloc(sizeof(Node)); tmp2->value=input; tmp2->next=tmp->next; tmp->next=tmp2; } tmp=list; return(list); } Node *append(Node*list) { //Append to list int input=0; Node*tmp; fprintf(stdout, "Enter what node you would like to append to: "); fscanf(stdin, "%d", &input); int behind; tmp=list; Node*tmp3=NULL; for(behind=0; behind<input; behind++) { tmp=tmp->next; } fprintf(stdout, "What value would you like to append: "); fscanf(stdin, "%d", &input); tmp3=(Node*)malloc(sizeof(Node)); tmp3->value=input; tmp3->next=tmp->next; tmp->next=tmp3; tmp=list; return(list); } Node *exile(Node*list) { int input=0; Node*tmp; tmp=list; Node*tmp2=NULL; int begone; fprintf(stdout, "Which node would you like to remove?: "); fscanf(stdin, "%d", &input); for(begone=0; begone<(input-1);begone++) { tmp=tmp->next; } if(input==0) { tmp2=tmp->next; tmp->next=NULL; list=tmp2; } else { tmp2=tmp->next; tmp->next=tmp2->next; tmp2->next=NULL; } tmp=list; return(list); } Node *display(Node*list) { int input=0; Node*tmp; tmp=list; while(tmp!=NULL) { fprintf(stdout, "[%d] %d -> ", input, tmp->value); tmp=tmp->next; input=input++; } fprintf(stdout, "NULL\n"); return(list); }
I also created the display backwards function for my doubly linked list program, shown below.
void displayb(List *myList) { Node *tmp=myList->end; int input=0; while(tmp !=NULL) { fprintf(stdout, "[%d] %d -> ", input, tmp->value); tmp=tmp->prev; input=input++; } fprintf(stdout, "NULL\n"); }
Today I had a great epiphany about functions. I finally realized that the “main” function is the only function that will be run by default. This will definitely lead to better understanding from future programs.
Today we continued on with our learning and discussed the insert function for the doubly linked list. We also started keeping all our user choices out of the functions themselves, this will make our functions more versatile for future uses.
The following is the code for the insert function itself
List *insert(List *myList, Node *place, Node *newNode) { if(place==myList->start) { newNode->next=place; place->prev=newNode; newNode->prev=NULL; myList->start=newNode; } else { newNode->next=place; place->prev->next=newNode; newNode->prev=place->prev; place->prev=newNode; } return(myList); }
The following is the if statement that leads to the insert function running. As you can see, all the decisions the user needs to make will happen before the function even runs.
else if(choice==2) { tmp=myList->start; fprintf(stdout, "Which node would you like to insert to$ fscanf(stdin, "%d", &choice); // seeker loop for(seeker=0; seeker<(choice-1); seeker++) { tmp=tmp->next; } // make new node (tmp2) // put choice in new node's value Node * tmp2 = (Node *)malloc(sizeof(Node)); fprintf(stdout, "What value would you like to insert: "$ fscanf(stdin, "%d", &choice); tmp2->value=choice; myList = insert(myList, tmp, tmp2); }
We created the remove function for the doubly linked list
List *getNode(List *myList, Node **place) { if(myList->start->next==NULL) { myList->start=NULL; } else if(*place==myList->start) { myList->start=myList->start->next; myList->start->prev=NULL; (*place)->next=NULL; } else if(*place==myList->end) { myList->end=myList->end->prev; myList->end->next=NULL; (*place)->prev=NULL; } else { (*place)->prev->next=(*place)->next; (*place)->next->prev=(*place)->prev; (*place)->prev=(*place)->next=NULL; } return(myList); }
and added the remove option to the menu
else if(choice==4) { tmp=myList->start; fprintf(stdout, "Which node would you like to remove: "$ fscanf(stdin, "%d", &choice); for(seeker=0; seeker<choice;seeker++) { tmp=tmp->next; } myList=getNode(myList, &tmp); }
Today we split our doubly linked list programs into separate files. One for the main function, one for the list functions, and a header. The contents of the header file are shown below.
#ifndef _DLL_H #define _DLL_H #include <stdio.h> #include <stdlib.h> struct node { int value; struct node *next; struct node *prev; }; typedef struct node Node; struct list { struct node *start; struct node *end; }; typedef struct list List; List *build(); void displayf(List*); void displayb(List*); List *insert(List *, Node *, Node *); List *append(List *, Node *, Node *); List *getNode(List *, Node **); #endif
I also fixed the append function of the doubly linked list
List *append(List *myList, Node *place, Node *newNode) { if(place==myList->end) { newNode->prev=place; place->next=newNode; newNode->next=NULL; myList->end=newNode; } else { newNode->prev=place; place->next->prev=newNode; newNode->next=place->next; place->next=newNode; } return(myList); }
Today was the day that I finally defeated the clear function for my singly linked list
Node *clear(Node*list) { Node *tmp = list; Node *tmp2; int count; while(tmp!=NULL) { tmp=tmp->next; count++; } tmp=list; for(; count>0 ; count--) { tmp2=tmp->next; tmp->next=NULL; free(tmp); tmp=tmp2; } return(NULL); }
This was great, a real step in the right direction. This joy was quickly dismantled when I started working on the sort function.
Node *sort(Node *list) { Node*tmp; Node*tmp2; tmp=list; Node *highest; int behind; int count = 0; while(tmp!=NULL) { tmp=tmp->next; count++; } int first=count-1; for(; first>0; first--) { tmp=list; tmp2=list; highest=tmp; count=first; for(; count>0; count--) { if(highest -> value < tmp2 -> value) { highest=tmp2; } tmp2 = tmp2 -> next; } // tmp = list; // while (tmp -> next != highest) // { // tmp = tmp -> next; // } //highest = tmp; list=exile(list, &highest); tmp = list; for(behind=0; behind<(first-2); behind++) { tmp=tmp->next; } list=append(list, tmp, highest); list=display(list); } return(list); }
Even after all this code, and other code added to append and remove, it still does not work. Hopefully soon I will be able to get this working.
Today in class we took part in a “knowledge assessment”. It has been yet to be seen how well I did on this but I feel like even if I got the end result wrong, the basic concepts down.
Today we did the “knowledge assessment” again! This time however we reviewed a little bit of the material beforehand. This resulted in very different answers from the first time around, I am feeling much better about this kind of code.
I also completed the most difficult, as of now, function of the singly linked list program, the sort. This was a multiple day problem and it is nice to see it finished, and to know that I actually understand a good amount of it.
Node *sort(Node *list) { Node*tmp; Node*tmp2; tmp=list; Node *highest; int behind; int count = 0; while(tmp!=NULL) { tmp=tmp->next; count++; } int first=count; for(; first>1; first--) { tmp=list; tmp2=list; highest=tmp; count=first; for(; count>0; count--) { if(highest -> value < tmp2 -> value) { highest=tmp2; } tmp2 = tmp2 -> next; } list=exile(list, &highest); tmp = list; for(behind=0; behind<(first-2); behind++) { tmp=tmp->next; } list=append(list, tmp, highest); } return(list); }
Today was the second half of the great knowledge assessment, but this time there was a twist. Instead of having the code and having to draw the list that it would create, this time we had to look at a picture and create the code that would create it. The code for Itme0x4,5, and 6 are found below.
Item0x4
#include <stdio.h> struct node { int value; struct node *next; struct node *prev; } struct list { List *start, *end; } Node *tmp, *tmp2, *mid; int main() { int count; tmp2 = create(); tmp = tmp2; tmp2 = list->start; tmp2->value = 16; for(count = 0; count<3; count++) { tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = (tmp->value)-4; tmp = tmp2; } tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 2; tmp = tmp2; mid = tmp2; for(count = 0; count<4; count++) { if(count == 0) { tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = (tmp->value)+1; tmp = tmp2; } else if(count == 3) { tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = (tmp->value)+4; tmp = tmp2; } else { tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = (tmp->value)+2; if((tmp2->value) == 5) { tmp2->prev = list->start->next->next; tmp = tmp2; } } } list->end = tmp; return(tmp); }
Item0x5
#include <stdio.h> struct node { int value; struct node *next; struct node *prev; } struct list { List *start, *end; } Node *tmp, *tmp2 *tmp3; int main() { int count; tmp2 = create; tmp = tmp2; tmp2->value = 3; list->start = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 1; tmp = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 4; tmp = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 1; tmp = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 5; tmp = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 9; tmp = tmp2; tmp2->next = create(); tmp2 = tmp2->next; tmp2->value = 2; tmp = tmp2; tmp2->prev = create(); tmp2->prev = tmp; tmp->value = 6; tmp->next = tmp2; tmp = tmp2; tmp3 = create; tmp3->value = 5; tmp3->next=tmp2; tmp2->next = list->start; return(tmp); }
Item0x6
#include <stdio.h> struct node { int value; struct node *next; struct node *prev; } struct list { struct node *start; struct node *end; } Node *tmp, *tmp2, *eye, *nose, *horn; int main() { int count; tmp = create(); tmp->value = 1; tmp = list->start; for( count = 0; count<11; count++ { if(count == 5) { tmp->prev = create(); horn = tmp->prev; horn->value = 3; horn->prev = tmp2; tmp->next = create(); tmp = tmp->next; tmp->value = 1; } else { tmp2 = tmp; tmp->next = create(); tmp = tmp->next; tmp->value = 1; } tmp = list->end; eye = create(); eye->value = 2; nose = create(); nose->value = 2; return(tmp); }
Main stack operations:
We created our push and pop functions for our stacks
push
#include "stack.h" Stack * push(Stack *myStack, Node *newNode) { if((*myStack->size <= 0) || (myStack->data->qty < myStack->size)) { (*myStack)->data = append((*myStack)->data, (*myStack)->data->e$ (*myStack)->top = (*myStack)->data->end; } return(myStack); }
pop
#include "stack.h" Node *pop(Stack **myStack) { Node *tmp = NULL; if(myStack != NULL) { tmp = getNode(&(*myStack)->data,(*myStack)->data->data->end); (*myStack)->top = (*myStack)->data->end; } return(tmp); }
We created a program to test our stack functions
nclude <stdio.h> #include "stack.h" int main() { Node *tmp; Stack *myStack; myStack = mkstack(0); tmp = create(); tmp->value = fgetc(stdin); fgetc(stdin); while(tmp->value != '\n') { myStack = push(myStack, tmp); tmp = create(); tmp->value = fgetc(stdin); fgetc(stdin); } fprintf(stdout, "linked list has %d nodes\n", myStack->data->qty); fprintf(stdout, "String is: "); do { tmp = pop(&myStack); if(tmp != NULL) { fprintf(stdout, "%c", tmp->value); } } while(tmp != NULL); fprintf(stdout, "\n"); return(0); }
Over the weekend I created two working functions for separate programs
The first was the sort function for the doubly linked list, which turned out to be exactly the same as the singly linked list sort function
List *sort(List *myList) { Node *tmp; Node *tmp2; tmp = myList->start; Node *highest; int behind; int count = 0; while(tmp != NULL) { tmp = tmp->next; count++; } int first = count; for(; first>1; first--) { tmp = myList->start; tmp2 = myList->start; highest = tmp; for(; count>0; count--) { if(highest->value < tmp2->value) { highest = tmp2; } tmp2 = tmp2->next; } myList = getNode(myList, &highest); tmp = myList->start; for(behind = 0; behind<(first-2); behind++) { tmp = tmp->next; } myList = append(myList, tmp, highest); } return(myList); }
The second function I created was the peek function for stacks
#include "stack.h" Stack *peek(Stack *myStack) { return(myStack->top); }
Today we worked on various programs trying to get our list and stack functions working properly.
I have discovered two problems with my porgrams
1) In the doubly linked list program, my clear function has a problem with a certain next pointer, it creates a problem after the first run through the loop
2) For the stacktest program, before the pop function runs myList→start = NULL and it is creating a segmentation fault
Today was a successful day, I officially finished my doubly linked list with the completion of my clear function and my stack test function is working perfectly.
Clear function
List *clear(List *myList) { Node *tmp = myList->start; Node *tmp2; int count; while(tmp != NULL) { tmp = tmp->next; } tmp = myList->start; for(; count>0; count--) { if(tmp == myList->end) { myList->end = NULL; myList->start = NULL; free(tmp); } else { tmp2 = tmp->next; tmp->next = NULL; tmp->prev = NULL; tmp2->prev = NULL; myList->start = tmp2; free(tmp); tmp = tmp2; } } myList->qty = 0; return(myList); }
Stack Test function
#include <stdio.h> #include "stack.h" int main() { Node *tmp; Stack *myStack; myStack = mkstack(0); tmp = mknode(0); tmp -> value = fgetc(stdin); fgetc(stdin); while(tmp->value != '\n') { myStack = push(myStack, tmp); tmp = mknode(0); tmp->value = fgetc(stdin); fgetc(stdin); } fprintf(stdout, "linked list has %d nodes\n", myStack->data->qty); fprintf(stdout, "String is: "); do { tmp = pop(&myStack); if(tmp != NULL) { fprintf(stdout, "%c", tmp->value); } rmnode(&tmp); } while(myStack->top != NULL); fprintf(stdout, "\n"); return(0); }
Today I created the functions for my queue
#include "queue.h" #include <stdio.h> Queue *mkqueue(int bufsize) { Queue *myQueue; myQueue = (Queue*)malloc(sizeof(Queue)); myQueue->data = mklist(); myQueue->bufsize = bufsize; myQueue->front = NULL; myQueue->back = NULL; return(myQueue); } Queue *enqueue(Queue *myQueue, Node *newNode) { if( (myQueue->bufsize <= 0) || ( (myQueue->data->qty) < (myQueue->bufsi$ { myQueue->data = append(myQueue->data, myQueue->data->end, newNo$ myQueue->back = myQueue->data->end; myQueue->front = myQueue->data->start; } return(myQueue); } Queue *dequeue(Queue **myQueue) { Node *tmp = NULL; if( (*myQueue) != NULL) { tmp = (*myQueue)->data->start; (*myQueue)->data = getNode( (*myQueue)->data, &tmp ); (*myQueue)->front = (*myQueue)->data->start; } return(myQueue); }
Started my card game program
#include <stdio.h> #include "stack.h" int main() { Stack *tableau[10]; Stack *foundation[8]; Stack *tmpdeck; Stack *deck; Stack *pile; tmpdeck = mkstack(0); deck = mkstack(0); pile = mkstack(0); tableau[0] = mkstack(0); tableau[1] = mkstack(0); tableau[2] = mkstack(0); tableau[3] = mkstack(0); tableau[4] = mkstack(0); tableau[5] = mkstack(0); tableau[6] = mkstack(0); tableau[7] = mkstack(0); tableau[8] = mkstack(0); tableau[9] = mkstack(0); List *mycards = ( List* )malloc( sizeof( List ) ); mycards->start = mycards->end = NULL; tmpdeck->data = mycards; Node *tmp; int suit = 1; int position; int seeker = 0; int count; int a = 0; //Creates the cards for the game while(mycards->qty != 104) { tmp = mknode(suit); tmpdeck->data = append(tmpdeck->data, tmpdeck->data->end, tmp); suit++; if(suit > 52) { suit = 1; } } tmp = tmpdeck->data->start;
Continued working on my card game program
//Takes 64 random cards out of the initial stack and puts them into the$ while(tmpdeck->data->qty != 40) { seeker = 1; position = rand()%tmpdeck->data->qty; while( seeker != position ) { if(tmp->next != NULL) { tmp = tmp -> next; } seeker++; } tmpdeck->data = getNode(tmpdeck->data, &tmp); deck->data = append(deck->data, deck->data->end, tmp); tmp = tmpdeck->data->start; } //Takes 4 random cards out of the intital stack and puts them into the $ while(tmpdeck->data->qty > 0) { for(count = 0; count < 4; count++) { seeker = 1; position = rand()%tmpdeck->data->qty; while( seeker < position ) { if(tmp->next != NULL) { tmp = tmp -> next; } seeker++; } tmpdeck->data = getNode(tmpdeck->data, &tmp); tableau[a]->data = append(tableau[a]->data, tableau[a]-$ tmp = tmpdeck->data->start; } a++; }
I made it so that my card game displays the tableaus in a vertical matter
fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n"); fprintf(stdout, "| | | | | | | | | | |\n"); fprintf(stdout, "| Deck | Pile | Di | Cl | He | Sp | Di | Cl | He | Sp |\n"); fprintf(stdout, "| %2d cards | %3d | %3d | %3d | %3d | %3d | %3d | %3d | %3d | %3d |\n", deck->data->qty, pile->top->value, foundation[0]->top->value, foundation[1]->top->value, foundation[2]->top->value, foundation[3]->top->value, foundation[4]->top->value, foundation[5]->top->value, foundation[6]->top->value, foundation[7]->top->value); fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n"); displayd(); fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n");
the displayd function
void displayd() { Node *tmp0 = tableau[0]->data->start; Node *tmp1 = tableau[1]->data->start; Node *tmp2 = tableau[2]->data->start; Node *tmp3 = tableau[3]->data->start; Node *tmp4 = tableau[4]->data->start; Node *tmp5 = tableau[5]->data->start; Node *tmp6 = tableau[6]->data->start; Node *tmp7 = tableau[7]->data->start; Node *tmp8 = tableau[8]->data->start; Node *tmp9 = tableau[9]->data->start; int a = 0; int b = 1; int count; int highest; for(count = 0; count != 9; count++) { if(tableau[a]->data->qty >= tableau[b]->data->qty) { highest = tableau[a]->data->qty; } else { highest = tableau[b]->data->qty; } a++; b++; } count = 0; while(count != highest) { if(tableau[0]->data->qty > count) { fprintf(stdout, "| %3d ", tmp0->value); tmp0 = tmp0->next; } else { fprintf(stdout, "|\t"); } if(tableau[1]->data->qty > count) { fprintf(stdout, "| %3d ", tmp1->value); tmp1 = tmp1->next; } else { fprintf(stdout, "|\t"); } if(tableau[2]->data->qty > count) { fprintf(stdout, "| %3d ", tmp2->value); tmp2 = tmp2->next; } else { fprintf(stdout, "|\t"); } if(tableau[3]->data->qty > count) { fprintf(stdout, "| %3d ", tmp3->value); tmp3 = tmp3->next; } else { fprintf(stdout, "|\t"); } if(tableau[4]->data->qty > count) { fprintf(stdout, "| %3d ", tmp4->value); tmp4 = tmp4->next; } else { fprintf(stdout, "|\t"); } if(tableau[5]->data->qty > count) { fprintf(stdout, "| %3d ", tmp5->value); tmp5 = tmp5->next; } else { fprintf(stdout, "|\t"); } if(tableau[6]->data->qty > count) { fprintf(stdout, "| %3d ", tmp6->value); tmp6 = tmp6->next; } else { fprintf(stdout, "|\t"); } if(tableau[7]->data->qty > count) { fprintf(stdout, "| %3d ", tmp7->value); tmp7 = tmp7->next; } else { fprintf(stdout, "|\t"); } if(tableau[8]->data->qty > count) { fprintf(stdout, "| %3d ", tmp8->value); tmp8 = tmp8->next; } else { fprintf(stdout, "|\t"); } if(tableau[9]->data->qty > count) { fprintf(stdout, "| %3d ", tmp9->value); tmp9 = tmp9->next; } else { fprintf(stdout, "|\t"); } fprintf(stdout, "|\n"); count++; } return(0); }
I updated my display function
void displayd() { int a = 0; tmp[a] = pile->top; fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n"); fprintf(stdout, "| | | | | | | | | | |\n"); fprintf(stdout, "| Deck | Pile | Di | Cl | He | Sp | Di | Cl | He | Sp |\n"); fprintf(stdout, "| %2d cards | %3s |", deck->data->qty, findfacesuitvalue(a)); for(a = 0; a < 8; a++) { tmp[a] = foundation[a]->top; } for(a = 0; a < 8; a++) { fprintf(stdout, " %3s |", findfacesuitvalue(a)); } fprintf(stdout, "\n"); fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n"); fprintf(stdout, "| Tableau0 | Tableau1 | Tableau2 | Tableau3 | Tableau4 | Tableau5 | Tableau6 | Tableau7 | Tableau8 | Tableau9 |\n"); tmp[0] = tableau[0]->data->start; a = 0; int b = 1; int count; int highest; for(count = 0; count != 9; count++) { if(tableau[a]->data->qty >= tableau[b]->data->qty) { highest = tableau[a]->data->qty; } else { highest = tableau[b]->data->qty; } a++; b++; } count = 0; for(a = 0; a != 10; a++) { tmp[a] = tableau[a]->data->start; } while(count != highest) { for(a = 0; a != 10; a++) { if(tableau[a]->data->qty > count) { fprintf(stdout, "| %3s ", findfacesuitvalue(a)); tmp[a] = tmp[a]->next; } else { fprintf(stdout, "|\t"); } } count++; fprintf(stdout, "|\n"); } fprintf(stdout, "|===========|===========|===========|===========|===========|===========|===========|===========|===========|===========|\n"); }
and my face value function
char *findfacesuitvalue(int a) { if(tmp[a]->value > 0 && tmp[a]->value < 14) { Card[2] = 'D'; Card[3] = '\0'; if(tmp[a]->value == 1) { Card[1] = 'A'; Card[0] = ' '; } else if(tmp[a]->value == 10) { Card[1] = '0'; Card[0] = '1'; } else if(tmp[a]->value == 11) { Card[1] = 'J'; Card[0] = ' '; } else if(tmp[a]->value == 12) { Card[1] = 'Q'; Card[0] = ' '; } else if(tmp[a]->value == 13) { Card[1] = 'K'; Card[0] = ' '; } else { Card[1] = (tmp[a]->value) + 48; Card[0] = ' '; } } else if(tmp[a]->value > 13 && tmp[a]->value < 27) { Card[2] = 'C'; Card[3] = '\0'; if(tmp[a]->value == 14) { Card[1] = 'A'; Card[0] = ' '; } else if(tmp[a]->value == 23) { Card[1] = '0'; Card[0] = '1'; } else if(tmp[a]->value == 24) { Card[1] = 'J'; Card[0] = ' '; } else if(tmp[a]->value == 25) { Card[1] = 'Q'; Card[0] = ' '; } else if(tmp[a]->value == 26) { Card[1] = 'K'; Card[0] = ' '; } else { Card[1] = (tmp[a]->value) + 35; Card[0] = ' '; } } else if(tmp[a]->value > 26 && tmp[a]->value < 40) { Card[2] = 'H'; Card[3] = '\0'; if(tmp[a]->value == 27) { Card[1] = 'A'; Card[0] = ' '; } else if(tmp[a]->value == 36) { Card[1] = '0'; Card[0] = '1'; } else if(tmp[a]->value == 37) { Card[1] = 'J'; Card[0] = ' '; } else if(tmp[a]->value == 38) { Card[1] = 'Q'; Card[0] = ' '; } else if(tmp[a]->value == 39) { Card[1] = 'K'; Card[0] = ' '; } else { Card[1] = (tmp[a]->value) + 22; Card[0] = ' '; } } else if(tmp[a]->value > 39 && tmp[a]->value < 53) { Card[2] = 'S'; Card[3] = '\0'; if(tmp[a]->value == 40) { Card[1] = 'A'; Card[0] = ' '; } else if(tmp[a]->value == 49) { Card[1] = '0'; Card[0] = '1'; } else if(tmp[a]->value == 50) { Card[1] = 'J'; Card[0] = ' '; } else if(tmp[a]->value == 51) { Card[1] = 'Q'; Card[0] = ' '; } else if(tmp[a]->value == 52) { Card[1] = 'K'; Card[0] = ' '; } else { Card[1] = (tmp[a]->value) + 9; Card[0] = ' '; } } else if(tmp[a]->value == 0) { Card[3] = '\0'; Card[2] = ' '; Card[1] = ' '; Card[0] = ' '; } return(Card); }
Added my draw card and move card functions
draw card
void newcard() { Node *tmp2; if(deck->data->qty != 0) { tmp2 = pop(&deck); pile = push(pile, tmp2); } else { fprintf(stdout, "Invalid move!\n"); } }
move card
void cardmove(Stack *pos1, Stack * pos2) { Node *tmp2; if(pos2->top == NULL) { tmp2 = pop(&pos1); pos2 = push(pos2, tmp2); } else if(pos1->top->value == (pos2->top->value)+1) { tmp2 = pop(&pos1); pos2 = push(pos2, tmp2); } else if((pos1->top->value) + 1 == pos2->top->value) { tmp2 = pop(&pos1); pos2 = push(pos2, tmp2); } else { fprintf(stdout, "Invalid move!\n"); } }
Changed the for loop that puts a node into each tableau so that the nodes have values that will make it so that only its corresponding suit will be able to be placed on to it.
for(a = 0; a < 8; a++) { if(a < 4) { //foundation[a]->data->start = NULL; tmp = mknode(b); foundation[a] = push(foundation[a], tmp); b = b + 14; } else { //foundation[a]->data->start = NULL; tmp = mknode(c); foundation[a] = push(foundation[a], tmp); c = c + 14; } }
Finished the menu for my card game and fixed all the problems with moving cards, it is now ready to be play tested.
The final menu
while(foundation[0]->data->qty != 14 && foundation[1]->data->qty != 14 && foundation[2]->data->qty != 14 && foundation[3]->data->qty != 14 && foundation[4]->data->qty != 14 && foundation[5]->data->qty != 14 && foundation[6]->data->qty != 14 && foundation[7]->data->qty != 14) { if(round != 0) { fgetc(stdin); } fprintf(stdout, "The commands for the game are, 'draw card' and 'move card'\n"); displayd(); fprintf(stdout, "What would you like to do?\n"); fgets(command, 10, stdin); fgetc(stdin); if(strcasecmp(command, "draw card") == 0) { newcard(); } else if(strcasecmp(command, "move card") == 0) { fprintf(stdout, "Do you want to take the card from the pile or a tableau?\n"); fscanf(stdin, "%s", choice1); if(strcasecmp(choice1, "pile") == 0) { fprintf(stdout, "Would you like to move the card to a foundation or a tableau?\n"); fscanf(stdin, "%s", choice2); if(strcasecmp(choice2, "foundation") == 0) { fprintf(stdout, "Which foundation?\n"); fscanf(stdin, "%d", &b); cardmove(pile, foundation[b]); } else if(strcasecmp(choice2, "tableau") == 0) { fprintf(stdout, "Which tableau?\n"); fscanf(stdin, "%d", &b); cardmove(pile, tableau[b]); } else { fprintf(stdout, "Invalid move!\n"); } } else if(strcasecmp(choice1, "tableau") == 0) { fprintf(stdout, "Which tableau?\n"); fscanf(stdin, "%d", &a); fprintf(stdout, "Would you like to move the card to a foundation or a tableau?\n"); fscanf(stdin, "%s", choice2); if(strcasecmp(choice2, "foundation") == 0) { fprintf(stdout, "Which foundation?\n"); fscanf(stdin, "%d", &b); cardmove(tableau[a], foundation[b]); } else if(strcasecmp(choice2, "tableau") == 0) { fprintf(stdout, "Which tableau?\n"); fscanf(stdin, "%d", &b); cardmove(tableau[a], tableau[b]); } else { fprintf(stdout, "Invalid move!\n"); } } else { fprintf(stdout, "Invalid input!\n"); } } else { fprintf(stdout, "Invalid input!\n"); } } round++;
Started my binary tree program, so far it can create the root of the tree
#include <stdio.h> #include "stack.h" List *displaytree(List *maple); List *addtree(List *pine, Node *pos1, Node *pos2); int main() { List *tree = ( List* )malloc( sizeof( List ) ); tree->start = tree->end = NULL; Node *root; int value0; int choice; fprintf(stdout, "What would you like for your root value? "); fscanf(stdin, "%d", &value0); root = mknode(value0); tree = append( tree, tree->start, root); tree = displaytree(tree); while(choice!=-1) { fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 1 to insert to tree |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 2 to remove from tree |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| 3 to display tree |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "| -1 to quit |\n"); fprintf(stdout, "|========================|\n"); fprintf(stdout, "Which would you like to do?\n"); fscanf(stdin, "%d", &choice); if(choice == 1) { int a; fprintf(stdout, "What value are you adding? "); fscanf(stdin, "%d", &a); Node * tmp = (Node *)malloc(sizeof(Node)); tmp->value = a; tree = addtree(tree, root, tmp); } else if(choice == 3) { displaytree(tree); } else if(choice == -1) { fprintf(stdout, "Goodbye\n"); } else { fprintf(stdout, "Error, Invalid Input\n"); } } return(0); } List *displaytree( List * maple) { Node *tmp1 = maple->start; Node *tmp2 = maple->start; fprintf(stdout, "\t%d\n", tmp1->value); if(tmp1->next != NULL || tmp1->prev != NULL) { tmp1 = tmp1->next; tmp2 = tmp2->next; while(tmp1->next = NULL) { fprintf(stdout, "\t%d\n", tmp1->value); fprintf(stdout, "\t%d\n", tmp2->value); } } return(maple); } List *addtree( List *pine, Node *pos1, Node *pos2) { while(pos1->next != NULL) { if(pos2->value < pos1->value) { fprintf(stdout, "Down Left"); pos1 = pos1->next; } else if(pos2->value > pos1->value) { fprintf(stdout, "Down Right"); pos1 = pos1->next; } } pos2 = pos1->next; pos1 = pine->start; return(pine); }
Fixed my binary tree adding function
List *addtree( List *pine, Node *pos1, Node *pos2) { int count = 1; while(count != pine->qty) { if(pos2->value < pos1->value) { if(pos1->prev != NULL) { fprintf(stdout, "Down Left\n"); pos1 = pos1->prev; } } else if(pos2->value > pos1->value) { if(pos1->next != NULL) { fprintf(stdout, "Down Right\n"); pos1 = pos1->next; } } else if(pos2->value == pos1->value) { } count++; } if(pos2->value < pos1->value) { fprintf(stdout, "Added a node to the left\n"); pos1->prev = pos2; pine->qty = (pine->qty) + 1; } else if(pos2->value > pos1->value) { fprintf(stdout, "Added a node to the right\n"); pos1->next = pos2; pine->qty = (pine->qty) + 1; } else { } pos1 = pine->start; return(pine); }
I created my remove function for the binary tree
List *taketree( List *willow, Node *pos ) { Node *tmp1 = willow->start; Node *tmp0; int count = 0; while(count != willow->qty) { if(tmp1->value > pos->value) { tmp0 = tmp1; if(tmp1->prev != NULL) { fprintf(stdout, "Down Left\n"); tmp1 = tmp1->prev; } } else if(tmp1->value < pos->value) { tmp0 = tmp1; if(tmp1->next != NULL) { fprintf(stdout, "Down Right\n"); tmp1 = tmp1->next; } } else if(tmp1->value == pos->value) { } count++; } fprintf(stdout, "tmp0 is %d\n", tmp0->value); fprintf(stdout, "Removing node %d\n", tmp1->value); if(tmp1->next != NULL && tmp1->prev != NULL) { Node *tmp2; if(tmp1->prev != NULL) { tmp2 = tmp1->prev; } else { tmp2 = NULL; } Node *tmp3; if(tmp1->next != NULL) { tmp3 = tmp1->next; } else { tmp3 = NULL; } if(tmp2 != NULL) { while(tmp2->next != NULL && tmp2->prev != NULL) { if(tmp2->next != NULL) { tmp2 = tmp2->next; } else { } } if(tmp1 == tmp0->prev) { tmp0->prev = tmp2; tmp2->next = tmp3; } else { tmp0->next = tmp2; tmp2->next = tmp3; } } else { while(tmp3->next != NULL && tmp3->prev != NULL) { if(tmp3->next != NULL) { tmp3 = tmp3->next; } else { } } if(tmp1 == tmp0->prev) { tmp0->prev = tmp3; tmp2->next = tmp2; } else { tmp0->next = tmp3; tmp2->next = tmp2; } } } else { if(tmp1 == tmp0->prev) { tmp0->prev = NULL; } else { tmp0->next = NULL; } } //tmp1->next = NULL; //tmp1->prev = NULL; free(tmp1); return(willow); }
I have it so that the display function for my binary tree outputs the first three levels of the tree, it will ultimately have to display five levels
List *displaytree( List * maple ) { Node *tmp0 = maple->start; Node *tmp1 = maple->start; Node *tmp2 = maple->start; Node *tmp3 = maple->start; Node *tmp4 = maple->start; Node *tmp5 = maple->start; Node *tmp6 = maple->start; fprintf(stdout, "\t\t\t\t\t\t\t%d\n", tmp0->value); if(tmp0->next != NULL || tmp0->prev != NULL) { fprintf(stdout, "\t\t\t\t\t"); if(tmp0->prev != NULL) { tmp1 = tmp0->prev; fprintf(stdout, "%d", tmp1->value); } else { } if(tmp0->next != NULL) { tmp2 = tmp0->next; fprintf(stdout, "\t\t\t\t%d", tmp2->value); } else { } fprintf(stdout, "\n"); fprintf(stdout, "\t\t\t\t"); if(tmp1->prev != NULL) { tmp3 = tmp1->prev; fprintf(stdout, "%d", tmp3->value); } else { } fprintf(stdout, "\t\t"); if(tmp1->next != NULL) { tmp4 = tmp1->next; fprintf(stdout, "%d", tmp4->value); } else { } fprintf(stdout, "\t\t"); if(tmp2->prev != NULL) { tmp5 = tmp2->prev; fprintf(stdout, "%d", tmp5->value); } else { } fprintf(stdout, "\t\t"); if(tmp2->next != NULL) { tmp6 = tmp2->next; fprintf(stdout, "%d", tmp6->value); } else { } fprintf(stdout, "\n"); } return(maple); }
I've been working on random EOC parts. All the C++ functions, my Doubly menu, Stack menu, and some binary tree functions have been finished.
Finished my Queue menu and my copy function for node
#include "node.h" Node * Node :: copy() { Node *tmp = new Node; Node *tmp2; tmp2 = this -> getNext(); tmp -> setNext(tmp2); tmp2 = this -> getPrev(); tmp -> setPrev(tmp2); int a = this -> getValue(); tmp -> setValue(a); return(tmp); }
On the first day of class we discussed the kind of projects that we would be completing over the semester. It would seem that throughout the semester we will be becoming very friendly with Raspberry Pi, which will allow us to accomplish a lot of the goals we will have. We also spent a good amount of time figuring what we will need for our Raspberry Pi's and began to set them up.
This is a photo of the Raspberry Pi, pre-construction.
This next photo shows the Raspberry Pi with some freshly added heatsinks, this will allow the Raspberry Pi to be overclocked.
This final photo shows the completed Raspberry Pi construction, please feel free to take a moment and absorb its beauty.
Today was a rather less productive day than I would have hoped. This was due to the fact the cases of the Raspberry Pi's needed to be dremeled so we could have access to the pins. “That sounds simple” is what you may be saying right now, and I would agree, except for the fact that our dremel was not working properly so we could not proceed as planned. The following are photos of the work we were able to accomplish.
Raspberry Pi prepared for dremeling
Failed dremel attempt
Today was the first time the Raspberry Pi's were set up to the monitors.
This is the set up of the Raspberry Pi
The beauty of the Raspberry Pi in full effect
Today was the day that the capabilities of the Raspberry Pi are starting to be shown.
We started to work on the first project of the class, which is to make an LED on GPIO pins work by using a command line approach. The code and photos for this project can be found in the Projects section of this opus.
This was a especially good day, in the way that it makes me excited for the rest of the class. I have honestly been worried about this class, due to my lack of experience with this kind of technology, but these future projects seem like they will be fun and I think I will have learned some great knowledge by the end.
Today we were greeted with the joyful news that we now have cables for the pins of our raspberry pi's. However as soon as we tried to insert the pins into them we learned that the holes that we dremeled into the top of the raspberry pi's are not big enough, http://www.youtube.com/watch?v=1ytCEuuW2_A . This was quickly resolved thanks to the work of a fellow classmate.
I also started working on the second project where I need to do the same thing as the first project only in a C program instead of using console commands.
Today I completed the second project which is the same as the first project only done in C. This was pretty difficult considering that the code we found had a few problems with it. All the specific details for this project can be found in the projects section of this opus.
Today I was the day of LED's. I started by preparing all my LED's for connection to the Raspberry Pi, complete with resistors and such. Next I made sure to connect the LED's to the correct pins and grounds, pins 8, 9, 10, and 11. I also color coded my LED's and taped them together to help with the clutter.
Today I completed my binary counter project. To first test my project I had the program ask the user what value they wanted to display as a binary number. This would test to see if the algorithm I created would evaluate the correct number. The completed code and some photos of the counter in action can be found in the projects section of this course.
Today was the first step in completing the third project. The first problem we have discovered is that we do not know how to get the raspberry pi to translate the pin signals being sent into the pins that the other raspberry pi is using. To start solving this problem I inserted a line to my code that will output the address of the pins that are being used when the different combinations of the LED are turned on.
We have made it so that the receiving Pi's LEDs are lighting up in the correct order, the only problem with this is that for the LEDs turning off we are manually doing it at the end of the code which means it does not know how to recognize the signals for LEDs that are turned off and turn off the correct LEDs.
Evan and I have officially finished our binary counter between two different Raspberry Pi's, the set up and code for the project will be found in the projects section for this course.
Various small work has been done on the Morse code project. We have made it so that our program can interpret a sentence and convert it into an appropriate Morse code signal. We have also made it make a single LED flash in relation to the signal being sent to the other Raspberry Pi. Right now we are working on how to take the signal that we are receiving and turn it back into the correct sentence. A lot of days have been derailed due to the security competition at Alfred State but now that that is over I'm sure we will be getting this project done quickly.