<html> <p>Well we spent a little time going over the concept of queues and talked a little bit about stacks again. Other than that I showed up an hour early due to forgetting what time I was supposed to be there… oh well haha. Anyway, I spent some of my time working on one of the experiments for my opus and got some more work done on that one. Other than that it was a pretty laid back day and we did work.</p> </html>
<html> We went over queues again and we were all like, they're sideways staxs, yo. They follow the FIFO ruling, which is first in, first out. And a nice example he gave us was planting a seed in the ground and watching it grow.
<pre> A little demonstration:
Enqueue - put stuff on it +- - - -+ |1|2|3|4| +- - - -+ Dequeue - get stuff off it
</pre> </html> And we also discussed a real life scenario for LIFO (Last in, first out) and it would be a pezz dispenser
And now for a little starter code
Node **dequeue(list *); void enqueue(list *, Node *);
<html> <p>Today we went over File i/o.</p>
<p>Files: Theory and Practice Also makes a good data structure topic</p> <p>Philosophy/Quote: “Everything is a file”</p> <p>3 Types of files</p> <ul style=“list-style-type: none;”> <li>Regular - Pretty much most things that we interact with on a daily basis</li> <li>Directory - A file that holds/has information of other files, it doesn't actually have any data itself</li> <li>Special - hardware such as harddrive and pipes and sockets on the software side. Also anything else that is not of the other 2</li> </ul> <p>Fields and records</p> <p>“Column and Rows”</p> <p>File Access/Operations</p> <ul style=“list-style-type: none;”> <li>Open</li> <li>Create</li> <li>Close</li> <ul style=“list-style-type: none;”> <li>read</li> <li>Write (>)</li> <li>Append (») - Moves the file pointer to the very end of the file</li> </ul> </ul> <pre> Some extra goodies: ————————————————————— r Open text file for reading. The stream is positioned at the beginning of the file. +r Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. +w Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. +a Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file. ————————————————————— </pre> </html> <file c> Example Program
#include <stdio.h>
int main() { FILE *fPointer; //Declare file pointer //fPointer = fopen("filename", "r"); //Opens the file, if there is a porblem it returns NULL, Check if the
pointer is NULL, if so, DONT PROCEED
fPointer = fopen("/etc/motd","r"); char value;
while((value = fgetc(fPointer)) != EOF) { printf("%c", value); } fclose(fPointer); return(0); }
</file>
I wasn't able to attend this class on this date due to some rather unforseen circumstances… There was a sudden death in the family and I was needed by my family.
But upon emailing the Great One, if there were to be a lecture today it would have been about Trees! And i thought I was only in one bio class this semester haha but anyway, here is what I know…
In a programming paradigm, unlike lists which use next and previous the common place formatting is to use right and left. The “bark” of a tree is to sort, preferably numbers. The lowest number on the left with the highest on the right as far down as it can go.
A little pseudo code example: ---------------------- if(value > current -> value) current = current -> right; else current = current -> left;
The C language allows us to perform integer addition or subtraction operations on pointers. If pointer1 points to an integer, pointer1 + 1 is the address of the next integer in memory after pointer. pointer - 1 is the address of the previous integer before pointer.
#include <stdio.h> #include <stdlib.h> int main() { int value = 10; int *pointer = &value; printf("Pointer: %d\n", pointer); printf("Pointer + 1: %d\n", pointer + 1); printf("Pointer + 2: %d\n", pointer + 2); printf("Pointer - 1: %d\n", pointer - 1); }
<html> <pre> Output:
Pointer: -2077239964 Pointer + 1: -2077239960 Pointer + 2: -2077239956 Pointer - 1: -2077239968 </pre> </html>
A void pointer is known as generic pointer, which can refer to variables of any data type.
#include <stdio.h> void use_int(void *); void use_float(void *); void greeting(void (*)(void *), void *); int main(void) { char ans; int i_age = 22; float f_age = 22.0; void *p; printf("Use int (i) or float (f)? "); scanf("%c", &ans); if (ans == 'i') { p = &i_age; greeting(use_int, p); } else { p = &f_age; greeting(use_float, p); } return 0; } void greeting(void (*fp)(void *), void *q) { fp(q); } void use_int(void *r) { int a; a = * (int *) r; printf("As an integer, you are %d years old.\n", a); } void use_float(void *s) { float *b; b = (float *) s; printf("As a float, you are %f years old.\n", *b); } //Found online and thought it was a really good example
<html> <pre> Output:
Use int (i) or float (f)? i As an integer, you are 22 years old.
Use int (i) or float (f)? f As a float, you are 22.000000 years old. </pre> </html>
A function pointer is a variable that stores the address of a function that can later be called through that function pointer. This is useful because functions encapsulates code so you dont have to keep re-writing it.
simply put, a pointer that points to a function.
#include <stdio.h> void myFunction(int x) { printf("%d\n", x); } int main() { void (*test)(int); test = &myFunction; test(2); //Or type (*test)(2) that will work also return 0; }
<html> <pre> Output:
2 </pre> </html>
These little guys point to a void in the space time continuum
#include <string.h> #include <stdio.h> //I think there might be an include that defines null... im not sure and if not then i guess you could make one? //The reason is because the output is a seg fault int main() { char *string = NULL; strcpy(string, "Test"); printf("%s", string); return 0; }
<html> <pre> Output:
Segmentation fault </pre> </html>
Free deletes the space of memory
//Taken from my doubly linked list star wars themed program if(force == yoda) { chewbacca = (sith_lord*)malloc(sizeof(sith_lord)); force -> anakin = chewbacca; chewbacca -> anakin = NULL; chewbacca -> darth_vader = force; chewbacca -> lightsaber = jedi_rank; yoda = chewbacca; free(chewbacca); }
“First in last out” Puts something on top of the stack, also a singly linked list
void push(Stack *pointer, int value) { Some stuff goes here }
Top of the stack
void push(stuff) { struct stack_test *temp; temp = (struct stack_test *)malloc(sizeof(struct stack_test)); temp -> data = x; temp -> next = top; top = temp; }
Last in First Out - This is how stacks work. FIFO (beinf First in First out) I believe is a queue
Adds elements to a queue
myQueue.enqueue("I am adding stuff to my queue")
Removes an element from a queue
myQueue.dequeue(some_stuff)
I will be taking the Singly Linked List and making it a Doubly Linked List… but wait… there's moar! It will be star wars themed! Oh, yeah!
Did the amount of brain pain equal out to the feeling of accomplishment… I tell you I had to take some advil with the massive headaches the ensued…
Writing it from scratch and constantly having to look back at things it took me about 5 hours in all to write this code… very time consuming and rather difficult… But I do feel like I did very well and learned quite a few things. I can look at the code and interact with it but I still need to look back at past examples of codes in order to write it out. But thats not a bad thing persay.
Reflect upon your results of the measurement to ascertain your achievement of the particular course objective.
#include <stdio.h> #include <stdlib.h> struct sith_lord { int lightsaber; struct sith_lord *darth_vader; //Pointer to the next Node in the list struct sith_lord *anakin; //Pointer to the previous Node in the list }; typedef struct sith_lord sith_lord; //just say jedi_council instead od struct jedi_council int main() { sith_lord *yoda, *force, *chewbacca; //start, current, temp //declaring three pointers for me to use of this struct type int jedi_rank; int i = 0; yoda = force = chewbacca = NULL; //making them all equal to NUL printf("Enter your rank (-1 to exit): "); scanf("%d", &jedi_rank); while(jedi_rank != -1) { if(jedi_rank == -1) break; if(yoda == NULL) { yoda = (sith_lord*)malloc(sizeof(sith_lord)); yoda -> darth_vader = NULL; yoda -> anakin = NULL; yoda -> lightsaber = jedi_rank; force = yoda; } else { force -> darth_vader = (sith_lord*)malloc(sizeof(sith_lord)); force -> darth_vader -> anakin = force; force = force -> darth_vader; force -> lightsaber = jedi_rank; force -> darth_vader = NULL; } printf("Enter your rank (-1 to exit): "); scanf("%d", &jedi_rank); } force = yoda; printf("Going Forwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); if ( force -> darth_vader != NULL ) force = force -> darth_vader; else break; i++; } printf("Going backwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); force = force -> anakin; i--; } //inserting a node into the struct printf("Enter a level to insert before: "); scanf("%d", &jedi_rank); force = yoda; for(i = 0; i < jedi_rank; i++) { force = force -> darth_vader; } printf("Enter a new rank: "); scanf("%d", &jedi_rank); if(force == yoda) { chewbacca = (sith_lord*)malloc(sizeof(sith_lord)); force -> anakin = chewbacca; chewbacca -> anakin = NULL; chewbacca -> darth_vader = force; chewbacca -> lightsaber = jedi_rank; yoda = chewbacca; //free(chewbacca); } else { chewbacca = (sith_lord*)malloc(sizeof(sith_lord)); chewbacca -> darth_vader = force; chewbacca -> anakin = force -> anakin; force -> anakin -> darth_vader = chewbacca; force -> anakin = chewbacca; chewbacca -> lightsaber = jedi_rank; /* force -> anakin -> darth_vader = chewbacca; chewbacca -> darth_vader = force; chewbacca -> anakin = force -> anakin; force -> anakin = chewbacca; chewbacca -> lightsaber = jedi_rank; */ //free(chewbacca); } force = yoda; i = 0; printf("Going Forwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); if ( force -> darth_vader != NULL ) force = force -> darth_vader; else break; i++; } printf("Going backwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); force = force -> anakin; i--; } //Appending printf("Enter the level to apend to: "); scanf("%d", &jedi_rank); force = yoda; for(i = 0; i < jedi_rank; i++) { force = force -> darth_vader; } printf("Enter a new rank: "); scanf("%d", &jedi_rank); if(force -> darth_vader == NULL) { chewbacca = (sith_lord*)malloc(sizeof(sith_lord)); //give birth to chewbacca force -> darth_vader = chewbacca; chewbacca -> darth_vader = NULL; chewbacca -> anakin = force; chewbacca -> lightsaber = jedi_rank; //free(chewbacca); //i want to free chewbacca... he deserves it... how can he escape? } else { chewbacca = (sith_lord*)malloc(sizeof(sith_lord)); chewbacca -> darth_vader = force -> darth_vader; force -> darth_vader = chewbacca; chewbacca -> darth_vader -> anakin = chewbacca; chewbacca -> anakin = force; chewbacca -> lightsaber = jedi_rank; } force = yoda; i = 0; printf("Going Forwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); if ( force -> darth_vader != NULL ) force = force -> darth_vader; else break; i++; } printf("Going backwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); force = force -> anakin; i--; } //Deleting printf("What rank would you like to delete: "); scanf("%d", &jedi_rank); force = yoda; for(i = 0; i < jedi_rank; i++) { force = force -> darth_vader; } if(force == yoda) { yoda = yoda -> darth_vader; force -> darth_vader = NULL; yoda -> anakin = NULL; free(force); } else if ( force -> darth_vader == NULL ) { force -> anakin -> darth_vader = NULL; force -> anakin = NULL; free(force); } else { force -> darth_vader -> anakin = force -> anakin; force -> anakin -> darth_vader = force -> darth_vader; free(force); } force = yoda; i = 0; printf("Going Forwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); if ( force -> darth_vader != NULL ) force = force -> darth_vader; else break; i++; } printf("Going backwards\n"); while(force != NULL) { printf("[%d] rank = %d\n", i, force -> lightsaber); force = force -> anakin; i--; } }
Using the JQuery library is it possible to create a random amount of shapes (circles in this case) with a random set of color fill and color edging?
<html> <body>
<a href="http://jquery.com/">JQuery API</a>
</body> </html>
I want to do something cool and challenging with JQuery, I believe this to be possible by attempting and hopefully being able to implement a way to draw random shapes (circles, im restricting myself so I dont go too overboard and have my brains blow up). Using canvas and its methods I will be able to draw things… at a click of a button!
<head> <title>Michael Short</title> </head> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#create").click(draw); $("#destroy").click(clear); }); function draw() { var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); for(i = 0; i <= 100; i++) { ctx.fillStyle = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")"; ctx.strokeStyle = "rgb(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ")"; ctx.lineWidth = "2"; var x = Math.floor(Math.random() * 500); var y = Math.floor(Math.random() * 500); var radius = 0.1 + Math.floor(Math.random() * 10); ctx.beginPath(); ctx.arc(x, y, radius, 0, Math.PI * 2, true); ctx.stroke(); ctx.fill(); } } function clear() { var ctx = canvas.getContext("2d"); ctx.clearRect(0, 0, 500, 500); } </script> <body> <canvas id="canvas" width="500" height="500" style="border: 3px solid red"></canvas> <button id="create">Draw</button> <button id="destroy">Clear</button> </body> </html>
<html> <body>
<a href="http://lab46.corning-cc.edu/~mshort3/jCircles/Lab10.html" target="_blank">Click here for the funz</a>Also, it will not work in IE
</body> </html>
Based on the data collected:
With canvas you can draw more than just circles, for example: rectangles, triangles, and smiley faces! And most likely many moar.
Can I… nay… Am I ready to take on some of HTML 5's new features… I say… YES!!! One new thing I'd like to see if I can do is draw using their new SVG tags or (Scalable Vector Graphics).
<html> <p>Before you can go any further you will need either one of two things:</p> <ul style=“list-style-type: none;”>
<li>Most recent version of Firefox (which, why wouldn't you?)</li> <li>Or you may have to go into the about:config page and enable HTML5 support (with the newest version you shouldn't have to do this though)</li>
</ul> <p>The Links!!! They be down below, arrrgghhh</p> <a href=“http://www.tutorialspoint.com/html5/html5_svg.htm” target=“_blank”>TutsPoints</a> </html>
With the growing support of the new HTML standard more and more browsers are starting to have support for the new HTML5 KING!!! I would like to perform one of its new features and see how it works and display browser compatibility.
<!DOCTYPE html> <head> <title>Some cool and new HTML5 stuff!!!</title> </head> <body> <svg id="svg1" height="200" xmlns="http://www.w3.org/2000/svg"> <rect id="redrect" width="300" height="100" fill="black" /> <!-- Draws the rectangle --> <circle id="redcircle" cx="50" cy="50" r="50" fill="red" /> <!-- Draws the circle --> <circle id="redcircle" cx="250" cy="50" r="50" fill="red" /> <!-- Draws the circle --> <text x="75" y="55" stroke="purple">Look, you can also put text in real easily!</text> </svg> </body> </html>
<html> <p>Follow the link below to behold the greatness!</p> <a href=“http://lab46.corning-cc.edu/~mshort3/html5/” target=“_blank”>Click Here</a>
<p>Browsers that support it… or at least have some support</p> <ul style=“list-style-type: none;”>
<li>Yes</li> <ul style="list-style-type: none;"> <li>Firefox</li> <li>Chrome</li> <li>Internet Explorer 9</li> </ul> <li>No</li> <ul style="list-style-type: none;"> <li>Opera (Although a newer version perhaps does support it... I don't use it enough (does anyone?)</li> </ul> <li>And im not sure on Safari... I dont have a mac...</li>
</ul> </html>
Based on the data collected:
There is plenty of room here to grow. Someone could make their own custom images. And with the promise of HTML5 to grow and expand over time I see the SVG and Canvas attributes becoming very popular.