User Tools

Site Tools


opus:spring2015:dsoutha3:start

Derek Southard's spring2015 Opus

TO POWERFULLY CONQUER THE STRENUOUS STRUGGLE OF DATA STRUCTURES!

Introduction

My goal is to be a successful software developer. I have been programming for about a year now, so there is still a whole lot more to learn. I hope that data structures brings my skills to the next level. Last but not least I hope to learn to make some awesome games in systems programming.

Data Structures Journal

Jan 27, 2015

So far, all I have really done for data structures is review, but don't get me wrong, I spent a good portion of time making this list options menu. Check it out!

1
#include <stdio.h>
#include <stdlib.h>
//declaring the fuctions I will be needing.
void displayList();
void Insert_AppendList();
void obtainList();
void clearList(); //without memset
 
int list[21];   //declaring some global vars, so I can use between funtions.
int choice,indexChoice,addedNumber,obtained,i=1;
 
int main()
{
	while (1) //infinite loop to wrap back to the menu.
	{	             //making output menu-styled.
	fprintf(stdout,"\n////////////////////////////////////////////\n// 1.Build\t  2.Display\t3.Insert \n// 4.Append into  5.Obtain from\t6.Clear\n// 7.Quit\n////////////////////////////////////////////\nMatch the list options menu number to the desired list and input HERE:  ");
	scanf("%d",&choice); 
	switch (choice) //switch statement to map menu choice to processes.
	{		
		case 1:
		while (list[i-1]!=-1)
		{
			if (i>=21) //limit to 20 numbers in index
			{
				list[21]=-1;
				printf("\nYour building list is full.\n");
				break;
			}
 
			if (i==1) //give directions first time around
			{
				printf("\nEnter numbers until you are done building your list (20 numbers max). When your list is done enter -1 to singnal the end of the list. INPUT FIRST NUMBER: ");
			}
			else 
			{
				printf("Next number: "); // continue prompting numbers
			}
			scanf("%d",&list[i]);
			i++; // go tonext element in array
		}
		break;
		case 2:
		displayList(); // print out list
		break;
		case 3:
		if(list[1]==0) // assume there is no list if first number is 0
	    {
			printf("OOPS! It looks like you don't have a list yet.\n");
			break;
		}
		printf("Where would you like to insert?(1-20): ");
		scanf("%d",&indexChoice);
		indexChoice--;
		printf("[Enter Number] index%d: ",indexChoice);
		scanf("%d",&addedNumber);
		Insert_AppendList(); //use to capture index before
		break;
		case 4:
		if(list[1]==0)
		{
			printf("OOPS! It looks like you don't have a list yet.\n");
			break;
		}
		printf("Where would you like to append?(1-20): ");
		scanf("%d",&indexChoice);
		indexChoice++;
		printf("[Enter Number] index%d: ",indexChoice);
		scanf("%d",&addedNumber);
		Insert_AppendList();//used to capture index after
		break;
		case 5:
		if(list[1]==0)
		{
			printf("OOPS! It looks like you don't have a list yet.\n");
			break;
		}
		printf("Which index number to obtain from?(1-20): ");
		scanf("%d",&indexChoice);
		obtainList(); 
		displayList();
		printf("\nNumber Obtained: %d\n",obtained); //print number obtained with function
		break;
		case 6:
		clearList();
		printf("\nLIST CLREARED\n");
		break;
		case 7:
		printf("\nList's will not be saved, ARE YOU SURE?\n(1.Yes|2.No)\n");
		scanf("%d",&indexChoice);
		if (indexChoice==1) //exit if selected with 1, otherwise continue with loop.
		exit(0);
		break;
		default://The default if none of the menu options are selected.
		fprintf(stderr,"\nINVALID MENU OPTON, read the menu and try again.\n");
		exit(1);
		break;
	}
}		
	return(0);
}
 
void displayList()
{						
	i=1;
	while(list[i]!=-1)
	{
		if(list[1]==0)
		{
			printf("OOPS! It looks like you don't have a list yet.\n");
			break;
		}
		else
		{
			printf("index%d: %d\n",i,list[i]); //navigate and print array
			i++;                               //until end of list marker.
		}
	}
}
void Insert_AppendList()
{
	int holder,holder2;
	i=indexChoice;
	if(i<21)
	{
		holder=list[i];
		list[i]=addedNumber;
		i++;
		while(i<21) // Buffers to insert and shift w/o losing data.
		{	
			holder2=list[i];
			list[i]=holder;
			i++;
			holder=list[i];
			list[i]=holder2;
			i++;
		}
	}
	else
	printf("\nYou are limited to 20 index's.\n");//incase try to store past 20
}
void obtainList()
{
	obtained=list[indexChoice]; // to obatin and erase.
	list[indexChoice]=0;
}
void clearList()
{
	i=1;
	while(i<=20)
	{
		list[i]=0;//set everything to 0.
		i++;
	}
}


Not bad for being rusty.

Feb 1 2015

I am just starting the next project, during the reading I found myself more intrested than i thought I would be. I am happy to be learning more advanced memory management, especially if it will make me extra amazing at higher level languages. Plus, it is neat how it all works. I won't post any work up here just in case it is tempting for somebody else in the course.

Feb 9 2015

Data structures, so far they aren't as hard as I anticipated, but they do prove pretty tricky; they also swallow up some time. Time is a valuable resource, but the skills aquired are certainly worth it. Keep in mind, I am only doing singly linked node lists, and creating simplistic node functions so far. I am hoping that this course can also get me efficient with using class types in c. Object oriented programming is one of my soft spots that I am looking to work on. As I am making a game in c++ in one course, I am making structs in this one. I can see both similarities and differences such as:

  • Only classes have member functions
  • Only classes have scopes such as private and public
  • They both name their own data type
  • With data structures, we cannot directly use inheritance and polymorphism without tricky methods

Feb 23, 2015

I finished up sll0, it was very painful, but with pain comes rewards. My major blocker was my mind-set. I kept believing that to make the list, I would need to gain memory for first and last, when in reality, all that needed to have memory was the list struct for the entire list. It was a mixture of only thinking in the box, and not really know what was intended. Actually, the final mklist() function is so simple, I couldn't believe I was actually hung up on it. This project has brought me a more open “useful container” kind of thinking about structs. I also gained more thought on how seperate structures can be powerfully used together. I love what I am learning, to way more efficiently and cleverly implent certain problems, that with previous knowelege would have led me to solve differently. So I implore you data strutures, BRING IT ON, for I shall mold and master my skills.

March 3, 2015

Now I kind of wish that I had never told data structs to bring it on. As the projects go further, the logic gets deeper. I am currently halfway through sll1, and my head is pounding (due to my throat swelling up.) I am trying to take it easier, but I just want to do it! but, I can't do it, because it hurts so bad!!! Oh the dilemna.

March 11, 2015

I am curently behind due to recent sickness, and am in hopes to catch-up. My main problem right now is that the unit tests are failing to link when compiled; therefore, they are non-existent. I don't know if it is the Makefile or what, but I will hopefully have that figure out by the end of tomorrow, and be well on my way. Another obstacle is cplist. Although I finally figured out that it was failing, because setpos was going NULL, a new problem has surfaced. cpnode works perfectly in the unit test, it doesn't keep the same adress, and it make a new node with the correct data stored in it. The problem is, somehow the way I am using it in cplist, it is keeping the same address, and just taking form of the same exat node. This is getting stressful, but I am confident I wil catch back up when I conquer this curve.

March 18, 2015

Although I hit brick wall after wall in this class, I am very proud of myself. Every break wall has made me much more skilled. I have also witnessed the gigantic power of writing psuedo code. Here is the are most elaborate embedded if statements I have ever written.

1
#include "list.h"
 
//////////////////////////////////////////////////////////////////////
//
// swapnode() - swap the position of two given nodes in a list, being
//              sure to appropriately adjust any and all pertinent
//              pointers to ensure list integrity following the
//              operation (including potential changes to the list's
//              own first and last pointers, along with connectivity
//              between the nodes from the start to end of the list).
//
//        note: you are NOT to just adjust node info values. You must
//              disconnect the identified nodes from the list and 
//              reconnect them- the node is our unit of transaction,
//              NOT the data it contains.
//
//    behavior: on a NULL list- do nothing: return NULL
//              on an EMPTY list- do nothing: return list unchanged
//              on a NULL/invalid nodes to swap- do nothing: return
//                  the list unchanged
//
//        note: where applicable, make use of the getpos() and
//              setpos() functions to aid you in accomplishing this
//              task. Don't needlessly reinvent the wheel.
//
//              as with the other functions, you may use no more
//              than one return() statement per function.
//
List *swapnode(List *myList, Node *item1, Node *item2)
{
	if(myList!=NULL)
	{
		if(myList->first!=NULL)
		{
			if(item1!=NULL&&item2!=NULL)
			{
				if(item1!=item2)
				{
					int pos; //declare variables, because swaps needed.
					Node *tmp=NULL;
					if(item1==myList->first)
					{
						if(item2==myList->last)//swapping first and last
						{
							pos=getpos(myList,item2); //mv last to prev
							myList->last=setpos(myList,(pos-1));
							myList->first=myList->first->after;
							item1->after=NULL;  //mv first to after
							myList->last->after=item1;  //mv Item1 to last
							myList->last=item1;      //adjust last to actual last 
						    item2->after=myList->first;//put item 2 before first
							myList->first=item2;//adjust first to actual first
						}
						else //swapping first and where ever in-between
						{
							myList->first=myList->first->after;
							item1->after=item2->after;
							if(item2!=myList->first)//if item 2 didn't become first
							{
								pos=getpos(myList,item2);
/*disconnet I2, connect I1*/	tmp=setpos(myList,(pos-1)); 
								tmp->after=item1;
								item2->after=myList->first; //re-connect item 1
								myList->first=item2; //adjust first to actual first
							}
							else //if item 2 became first
								myList->first->after=item1; //connect item completely
						}
					}
					else if(item2==myList->first) //inverse of if item 2 was first
					{							
						if(item1==myList->last) 
						{
							pos=getpos(myList,item1);
							myList->last=setpos(myList,(pos-1));
							myList->first=myList->first->after;
							item2->after=NULL;
							myList->last->after=item2;
							myList->last=item2;
							item1->after=myList->first;
							myList->first=item1;
						}
						else 
						{
							myList->first=myList->first->after;
							item2->after=item1->after;
							if(item2!=myList->first)
							{
								pos=getpos(myList,item1);
								tmp=setpos(myList,(pos-1));
								tmp->after=item2;
								item1->after=myList->first;
								myList->first=item1;
							}
							else
								myList->first->after=item2;
						}
					}
					else if(item1==myList->last)  //final checks for if they are first or last, checking if a single items last &
					{                                                                              //none are first
							pos=getpos(myList,item1);
							myList->last=setpos(myList,pos-1);
							item1->after=item2->after;  
							myList->last->after=NULL; //moving last back 1 and pointing item 1 to what item 2 points to
							pos=getpos(myList,item2); 
							tmp=setpos(myList,pos-1); 
							tmp->after=item1; //dis-connecting item 2 and totally connecting item 1
							myList->last->after=item2;
							myList->last=item2; //moving item 2 to last pos and re-adjusting last pointer			
					}
					else if(item2==myList->last) //inverse of last check
					{	
						pos=getpos(myList,item2);
						myList->last=setpos(myList,pos-1);
						item2->after=item1->after;
						myList->last->after=NULL;
						pos=getpos(myList,item1);
						tmp=setpos(myList,pos-1);
						tmp->after=item2;
						myList->last->after=item1;
						myList->last=item1;
					}
					else //IF neither nodes are first nor last
					{
						pos=getpos(myList,item1);
						tmp=setpos(myList,(pos-1));
						tmp->after=item1->after;  //disconnect item1
						item1->after=item2->after;
						pos=getpos(myList,item2);
						Node *tmp2=setpos(myList,pos-1); //because tmp still holds place for item 1
						tmp2->after=item1; //re-connecting item1 whilst dis-connecting 2
						item2->after=tmp->after;
						tmp->after=item2;  //re-connecting item to where item 1 was
					}
				}
			}
		}
	}
 
 
 
 
	return(myList);
}

March 25, 2015

I am now finishing up sll3. Thus, I am pretty much caught up, and feeling pretty well about it. I have come a long way! At the end of sll2, I hit a huge brick wall. No matter what, I kept getting a problem in the unit test while trying to perform bubble sorts on the singly linked list. I was using a couple of list functions, and didn't even think twice about swapnode being the problem. I had beleived it to be a master-piece, but it was not (yet). I spent hours searching for why I was getting a memory leak, and seemingly infinite list. Finally, I got to where I did test swap nodes funtionality for the specific condition.


1
 99:                     else if(item1==myList->last)  //final checks for if they are first or last, checking if a single items last &
100:                     {                                                                              //none are first
101:                             pos=getpos(myList,item1);
102:                             myList->last=setpos(myList,pos-1);
103:                             item1->after=item2->after;
104:                             myList->last->after=NULL; //moving last back 1 and pointing item 1 to what item 2 points to
105:                             pos=getpos(myList,item2);
106:                             tmp=setpos(myList,pos-1);
107:                             tmp->after=item1; //dis-connecting item 2 and totally connecting item 1
108:                             myList->last->after=item2;
109:                             myList->last=item2; //moving item 2 to last pos and re-adjusting last pointer
110:                     }



You see, I never disconnected what item2 was pointing to (major problem for this funtionality). I believe I could have simply set item2→after to NULL, but I re-wrote this to be more stable all together. As you can see below.

1
                        {                           
                            pos=getpos(myList,item2);
                            tmp=setpos(myList,pos-1);  
                            tmp->after=tmp->after->after; 
                            item2->after=NULL;
                            myList->last->after=item2; //dis-connecting item2 and putting it at the end of list
                            myList->last=item2;    //maintain list integrity
                            if(item1!=tmp->after)
                            {
                            item1->after=tmp->after; //put item 1 where item 2 was, if not already
                            tmp->after=item2;
                            }
 
                          }


I felt proud when I made all of this work, this is my weeks reflection.

April 16, 2015

I am proud of myself, I have went trough all of the dll projects with only on BRICK WALL. This was where I went to the reverse list in sort. I couldn't make a copy of the list in this project, so I wasn't allowed to copy the list backward, so I tried to swap the nodes last and first until they got to the middle. I couldn't get that to work, so I tried just switching first and last, then I realized how much of a pain it would be to change all of the double links. Finally, I did some real problem solving, looked in other functions, and found the way I made swap so short, and efficient was making the algorithm in sort lose its place. I added a couple extra temporary pointers, and voila! Problem FIXED!

Systems Programming Journal

Jan 27, 2015

  • What action or concept of significance, as related to the course, did you experience on this date?
  • I remade a screen using SDL2. I was going to load images and do more, but I am stuck for tonight.
  • Why was this significant?
  • I tought myself a couple things on preventing memory leaks on heap.
  • What concepts are you dealing with that may not make perfect sense?
  • Installing, and figuring out how to link libraries! It's making me nuts and wasting hours of time.
  • What challenges are you facing with respect to the course?
  • Just the above mentioned problem.

Feb 1, 2015

I am working on switching from SDL 1 to 2, and it seems to be a pain. The concepts are similar, but at the same time it is all different. It is certainly a learning cure. Hopefully I have moving asteroids on the screen and everything else organized.

Feb 9, 2015

I have finally triumphed over the learning curve of SDL2, and also discovered a lot of the problem was, because I had barely remembered SDL1 correctly. So far, I have,in my opinion, some awesome code that loads SDL Surface images in arrays, that are sorted by size. Then blits them to the screen in random locations, inside of an event loop using an SDL Rect array. Furthermore, they all get assigned random velocities using an asteroid member functionand their SDL_Rects that they were blitted with. They are even wrapping around the screen with the same general if statements in a loop.

March 3, 2015

I have learned a lot with getting the template to this asteroids game finish. I have almost all of the computer elements working, more funationaly than I had expexcted. If I wasn't basically alone, I would have had the player doing some amaing things into the game. I poured my time and soul, and learned a lot of logic which can be implemented in the next game that I participate in. I plan on finishing this one off eventually, when i have the time.

March 11, 2015

I am about to start working on a new game, that implemets space travel, and spaceship combat. I am excited for this one, because we have an entire class for collaborators. I plan on starting code when I learn about it more in class tomorrow. This will be a good one. We will be using c++ and sld2 again.

March 18, 2015

Everyone seems to be taking their time getting into this game, so far we have a screen established, and an image loaded. I myself, have been very tied up with data structures, but plan on writing some code for it tomorrow.

March 25, 2015

This week up updated the Makefile, for an include file, and an additional lib. I also added a an INC folder. Additionally, I fixed a few things with the image rendering in the poll event, and fixed the given parameters to similar SDL functions. I plan on resizing the screen, and creating four sectors.

April 16, 2015

There is not much to say that hasn't been said other than, we have been implementing some pretty sweet functionality. These programs include are very own chmod, grep, get opt, and even learning about making a man page.

opus/spring2015/dsoutha3/start.txt · Last modified: 2015/01/20 00:53 by 127.0.0.1