User Tools

Site Tools


opus:fall2012:lalexan3:part2

Part 2

Second month: starting stacks

Entries

Entry 1: October 12, 2012

First week of October:

i am still working on making sure that my doubly linked lists are working correctly and i cannot seem to figure out what is going on with the deletion portion of my code. There also seems to be a problem with making the list print backwards as well and i couldnt find the problem with appending my code before the first node. Meeting with saad later this week.

i still am having problems with understanding how to write code but i seem to be able to read my code and see the problems with it i just cant figure out how to fix the code with more code or make changes to my code to improve it.

the challenges that i seem to be facing this week is still how to get started writing my own code. Not totally sure what the syntax is for writing any code at this point.

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Entry 2: October 19, 2012

Today is friday and there is not much going on in class today. I was able to fix my code on tuesday and thursday while working with saad this week so i finished my code and its working on all counts now. Fill list didnt have a counter to keep track of the list after is was filled to print the list backwards. Deletion was having a problem with deleting the last node but that was because i had tmp = *end rather than the other way around so it was not printing out the last node but i fixed that too.

so i am all set for taking my test on doubly linkedx list but it seems that i am the only one today besides saad soo i guess ill have to wait till next wednesday to finish that so ill write more next week when i forsee my having problems with stacks. I actually have the header file done and am working on the menu portion and push as awell as pop functions.

I think that i will call the stacks themselves skyscraper becuase they are going to be really tall unlike linkedlists that are long. Basically the difference between vertical and horizontal.

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Entry 3: October 24, 2012

Today is Wednesday and i am preparing for the knowledge assessment. Learning to read the code and figure out what it is telling me to do has been a very interesting road but its working out OK i thought. Then i took the graded assessment in class and it went very badly.

I am also working on making the stacks program actually compile. Its funny because even though linked lists and stacks are almost the same thing i am still having trouble getting the program to compile.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Entry 4: October 28, 2012

I finally got my program to compile and its running fine. I pushes nodes onto the stack and deletes nodes from the stack but i am missing something because it wont display the popped numbers from the stack and delete the node as well. so i have spend the last three days getting my code working and getting it to print out exactly what i want to see. it going well but still have a couple of problems.

As an aid, feel free to use the following questions to help you generate content for your entries:

  • What action or concept of significance, as related to the course, did you experience on this date?
  • Why was this significant?
  • What concepts are you dealing with that may not make perfect sense?
  • What challenges are you facing with respect to the course?

Remember that 4 is just the minimum number of entries. Feel free to have more.

Keywords

data Keyword 2

! queue data structure !!!!

Definition

Queue Data Structure

Queue is a specialized data storage structure (Abstract data type). Unlike, arrays access of elements in a Queue is restricted. It has two main operations enqueue and dequeue. Insertion in a queue is done using enqueue function and removal from a queue is done using dequeue function. An item can be inserted at the end (‘rear’) of the queue and removed from the front (‘front’) of the queue. It is therefore, also called First-In-First-Out (FIFO) list. Queue has five properties - capacity stands for the maximum number of elements Queue can hold, size stands for the current size of the Queue, elements is the array of elements, front is the index of first element (the index at which we remove the element) and rear is the index of last element (the index at which we insert the element).

Queue is a data structure that maintain “First In First Out” (FIFO) order. And can be viewed as people queueing up to buy a ticket. In programming, queue is usually used as a data structure for BFS (Breadth First Search). Queue operations

Operations on queue Q are :

1. enqueue - insert item at the back of queue Q 2. dequeue - return (and virtually remove) the front item from queue Q 3. init - intialize queue Q, reset all variables.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

data Keyword 2 Phase 2

stack push operation

Definition

The push operation adds a new element to the top of the stack (FILO)First in Last Out. You can also push until the array is full stack overflow, or you can pop until the array is empty stack underflow.

References

List any sites, books, or sources utilized when researching information on this topic. (Remove any filler text).

* http://www.cplusplus.com/reference/stl/stack/push/

* http://en.wikipedia.org/wiki/Stack_(abstract_data_type)

Demonstration

Demonstration of the indicated keyword.

If you wish to aid your definition with a code sample, you can do so by using a wiki code block, an example follows:

#include<stdio.h> #include<stdlib.h> /* Stack has three properties. capacity stands for the maximum number of elements stack can hold. Size stands for the current size of the stack and elements is the array of elements */ typedef struct Stack { int capacity; int size; int *elements; }Stack; /* crateStack function takes argument the maximum number of elements the stack can hold, creates a stack according to it and returns a pointer to the stack. */ Stack * createStack(int maxElements) { /* Create a Stack */ Stack *S; S = (Stack *)malloc(sizeof(Stack)); /* Initialise its properties */ S→elements = (int *)malloc(sizeof(int)*maxElements); S→size = 0; S→capacity = maxElements; /* Return the pointer */ return S;}void pop(Stack *S){ /* If stack size is zero then it is empty. So we cannot pop */ if(S→size==0) { printf(“Stack is Empty\n”); return; } /* Removing an element is equivalent to reducing its size by one */ else { S→size–; } return; } int top(Stack *S) { if(S→size==0) { printf(“Stack is Empty\n”); exit(0); } /* Return the topmost element */ return S→elements[S→size-1]; } void push(Stack *S,int element) { /* If the stack is full, we cannot push an element into it as there is no space for it.*/ if(S→size == S→capacity) { printf(“Stack is Full\n”); } else { /* Push an element on the top of it and increase its size by one*/ S→elements[S→size++] = element; } return;}int main() { Stack *S = createStack(5); push(S,7); push(S,5); push(S,21); push(S,-1); printf(“Top element is %d\n”,top(S)); pop(S); printf(“Top element is %d\n”,top(S)); pop(S); printf(“Top element is %d\n”,top(S)); pop(S); printf(“Top element is %d\n”,top(S));

Experiment 2

Question

What is the question you'd like to pose for experimentation? State it here.

I wonder what would happen if i were to make a number guessing game that would have the computer pick a decimal number between 0 and 9, then I input my guess and see how long it will take for me to guess what number the computer picked at random.

Resources

Collect information and resources (such as URLs of web resources), and comment on knowledge obtained that you think will provide useful background information to aid in performing the experiment.

I would require a computer that has internet access and i will need a pencil and paper, as well as a person.(me)!!!

Hypothesis

Based on what you've read with respect to your original posed question, what do you think will be the result of your experiment (ie an educated guess based on the facts known). This is done before actually performing the experiment.

State your rationale.

I think that the result of my experiment will allow the user to input guesses and have the computer give a response to whether or not the inputed guess is too high, too low, or correct. it will also promt the user to play the game again.

Experiment

How are you going to test your hypothesis? What is the structure of your experiment?

I think that after i actually create the number guessing game it will prolly take time to get the program to compile but once it does it will work out well and will be a fun game to play. I will input random numbers between 0 and 9 and make sure that it gives me back the correct response.

Data

Perform your experiment, and collect/document the results here.

int main(void){ int stime; long ltime; int thisRandomNumber; int userinput; /* get the current time and then send the random number */ ltime= time(NULL); stime= (unsigned) ltime/2; srand(stime); calculate a random number between 1 and 10 */ thisRandomNumber= rand() %10 + 1; printf(“Guess the random computer generated number:\n”); scanf(“%d”,&userinput); if (userinput == thisRandomNumber){ printf(“That's the number!\n”); } else if (userinput > thisRandomNumber){ printf(“Your guess is higher than the number.\n”); } else if(userinput < thisRandomNumber){ printf(“Your guess is lower than the number.\n”); } return 0; } ====Analysis==== Based on the data collected: * Was your hypothesis correct? YES * Was your hypothesis not applicable? NO * Is there more going on than you originally thought? (shortcomings in hypothesis): YES IT TENDS TO CLOSE OUT AFTER YOU RUN THE PROGRAM ONCE. * What shortcomings might there be in your experiment? I DIDNT consider WHETHER or NOT I wanted THE computer TO run IT through AGAIN after THE first TIME I ran IT. * What shortcomings might there be in your data? I DIDNT INPLEMENT Any method into the LOOP so that IT WONT exit the game AFTER YOU PLay THE GAME ONCE. ====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.: It takes several guesses to get it right but its reletivley easy and im glad i got the idea.

opus/fall2012/lalexan3/part2.txt · Last modified: 2012/10/31 02:13 by lalexan3