======Part 2====== =====Entries===== ====Entry 1: October 5th, 2012==== This week has been a work week on doubly linked lists. Working on a menu driven program that do the same thing as a singly but instead of only moving forward, it can transverse both forward and backwards. I am going to try this project differently by instead of following the nodes, it will follow the content inside. The only obstacle i will have to face is getting over duplication of numbers so we shall see. In my data comm class we are still working on asterisk, finding new implementations everyday! and for HPC, well.. i should do more work with that ====Entry 2: October 12th, 2012==== This week we have actually learned some new things! We learned stacks, which are like containers that hold data and spit back out. But it acts differently, like it takes in the data but the last piece to go in is what comes out first. So it reverses the data that is entered and this can be used in certain instances. Another thing we learned is recursion, where a function calls itself so it will loop within itself until it hits a stopping point! This is very useful and i actually will be using it in my list because i believe it will come in handy printing out a list backwards, so will a stack but i dont completely understand it yet with the push and pop functions. Data comm and HPC are still the same where they are, working on asterisk and not working on my drum machine.. i need to step it up or else its going to be a bad time. I just cant get arduino to work! ====Entry 3: October 19th, 2012==== This is week is another work week but our doubly linked menu were due. And mine was pretty boss, i am now called the recursion king! Just to let you all know. But seriously i got recursion to work in my program and it was a very different implementation then the other programs and i was quite proud of it. Now i just need to work on my stack program, which now i do understand more and i will have to start working on it very soon. We havent really learned anything else, just a test and working on programs. Nothing else. Still trying to get arduino to work on linux and i am having no luck, it wont execute files for some reason for to run the program. Like it wont download the software i need, i have to look deeper in i guess. And i kind of miss data comm this week and came back to working on something new with sound files and images. We will see where this goes lol ====Entry 4: October 26th, 2012==== This week has been an interesting week, with hurricane sandy coming through. So most of our projects were pushed ahead a week so thats good because i procrastinate a lot :D but other then that, we learned about a binary tree sort, which doesnt seem to hard conceptually but implementing it might be difficult. We can either use recursion, iteration or stacks and you better believe im using recursion, i want to get better with them. So after this stacks program is done i will be doing research on the binary tree and start headway onto the project that will be put out in the future. For HPC i am still stuck on making any headway into this project, i just dont understand why i cant access the software or my sound driver, im in a rut. And for data comm i am not totally sure whats going on because i missed class because of the hurricane so i dont know what we are doing yet! =====Keywords===== {{page>datapart2&nofooter}} {{page>datacommpart2&nofooter}} {{page>hpc1part2&nofooter}} =====Experiment 2===== ====Question==== Is it possible to convert decimal to binary using recursion instead of loops? ====Resources==== As the recursion king i am using my knowledge to put forth new experiments into my kingdom. Recursion is where a fucntion will call itself and loop till it reaches a sentinel value and will print out your data, recursively! Now i will be doing a decimal to binary conversion, which is simple to do by hand and or even write out an algorithm on a computer. Here is a bash script that was written that converts decimal to binary: 1 #!/bin/bash 2 a=0 3 echo -n "please enter a number: " 4 read number 5 until [ $number -eq 0 ];do 6 n=0 7 until [ `echo "$number-2^$n"|bc` -lt 0 ];do 8 let n=$n+1 9 done 10 let n=$n-1 11 let number=$number-`echo "2^$n"|bc` 12 places="" 13 for((i=0;i<$n;i++));do 14 places="${places}0" 15 done 16 places="1${places}" 17 let a=$a+$places 18 done 19 echo "the binary is: $a " 20 exit 0 This is a example of the algorithm that is used in converting these numbers and it will be used in this experiment just taken a different way, without loops! :D ====Hypothesis==== I believe it can easily be done, with the algorithm i know that can solve this problem, i believe with the implementation that i will be using will make this easy, in fact even easier then loops and if statements! ====Experiment==== Im going to write the program, compile it, and run it and see if it works! ====Data==== 1> Write the code: 1 #include 2 #include 3 4 5 int binary(int); 6 7 int main() 8 { 9 10 int nb; /*This is number binary, its just a variable the name doesnt really matter*/ 11 int nd; /*this is number decimal and same here lol*/ 12 13 printf("Please enter any decimal number: "); 14 scanf("%d", &nd); 15 16 nb = binary(nd); 17 printf("Binary value is: %d\n", nb); 18 19 return 0; 20 } 21 22 int binary(int nd) 23 { 24 25 static int nb,remainder,factor = 1; 26 27 if(nd != 0) 28 { 29 remainder = nd % 2; 30 nb = nb + remainder * factor; 31 factor = factor * 10; 32 binary(nd / 2); 33 } 34 return nb; 35 36 } 2. Execute code: lab46:~/src/datastruc$ ./binaryrecursion Please enter any decimal number: 10 Binary value is: 1010 lab46:~/src/datastruc$ Side note to you and mainly myself lol: The static was used because when the fucntion calls itself it actually loses the data that was held with the remainder, factor and nb. So i looked up what to do about that and static was one, which keeps the data held there long after the scope of the fucntion is over so when it is called again we can still have that data and it will be good to go! Or also, i could have passed them all through the fucntion and made it a void so i wouldnt run into that issue, but both ways will work just fine. ====Analysis==== Based on the data collected: * My hypothesis was correct! * My hypothesis is very applicable because it worked, duh :) * Umm no not really, i knew what was going on i was just seeing if this was possible * There might be more going on that i really know or understand, but other than that, i understand what is happening. * It may not go high enough for certain numbers since it is using int data value, but it still works just like it is suppose to work. ====Conclusions==== What can you ascertain based on the experiment performed and data collected? Document your findings here; make a statement as to any discoveries you've made.