HOME

CS 2511

CS 3810

CS 4600

CS 5610

CS 3810
STUDENT WEBPAGES
CS 3810
ASSIGNMENTS
CS 3810
TEST REVIEW
CS 3810
CLASS NOTES

CLASS NOTES FOR
DATA STRUCTURES

9/10/02 | 9/17/02| 9/19/02| 9/26/02| 10/22/02| 11/12/02|

CLASS NOTES FOR 9/10/02

Data Structures = Structure of Data

Queue (Q) = First choice is first (First come first serve)

Stack = Last one first

Algorithm = A way to solve a problem by programming.

 

 

 

- Array is one of the most important Data Structures

- Array is used to BUILD (For example, A person can build a Stack, Queue, Tree, or a Graph (also known as Network)

 

1)      Name one application for each of Data Structure.

Graph is used for Networking

Stack is used in cascading of windows

Queue is use for Printers, memory and voicemail

 

2)    Conversion of Infix to Postfix

Postfix = 2, 3 +

Prefix = +2

           

            Old Calculator were either postfix or prefix but not infix

            Postfix and Prefix doesn’t need prantheses when programming

            APL reads from Right to Left

            One of the problem of Data Structure is conversion of Infix to Postfix

            Opreators are + * - /

 

3)      How do you evaluate Postfix Notation?

In Postfix order is not important

            When there is a number push, when a operator pop (pop and push belongs to Stack)

 

BACK TO THE MAIN MENU....






CLASS NOTES FOR 9/17/02

Stack

Main Data StructuresQueue

Tree

Graph

AlgorithmsSearching

Sorting

 

1)   Which of the following program is better?

a)

cout<<”Enter Your Name”; char name [15]

cin>>name; int age

cin>> age; float salary

 

OR

 

b)

cout<<”Enter your Name”;                                struct person

cin>>employee.name;                                         {

cin>>employee.age;                                            char name [15]

                                                                                int age

float salary

}

person employee

 

 

Choice b is a better form of programming because it has structure to it.

 

Infix Evaluation

2 3 4 * +

Algorithm = If digit then PUSH

                                else

                                if operator

                                pop

                                pop

                                evaluate

                                push

                                else no more, pop

                                DISPLAY

 

How would make a stack?

Array

176 786 664

 

0 1 2 3

 

Stack

number [0] = 176

number [1] = 786

number [2] = 664

number [i]

                i++;

stack [i]

                i++;

 

change i to top

 

stack[top] = X

top++;

 

1)       Write a function called Push?

Int stack [10];

Int top = 0;

Int x;

Push (){

Stack [top] = x

Top++;

}

main()

{

push();

}//main

 

2)       2 ways to use stack are Array and Pointer

SIMPLE STACK MENU

 

#include<iostream.h>

void push (int mystack[],int & mytop,int item){

        mystack[mytop]=item;

        mytop=mytop+1;} //PUSH

int pop(int mystack[],int &mytop){

        mytop=mytop-1;

        int item=mystack[mytop];

        return item; }//POP

int isempty(int mytop){

        if(mytop==0) return 1;

        else return 0;}//ISEMPTY

int isfull(int mytop,const int MAXSTACKSIZE){

        if(mytop==MAXSTACKSIZE)return 1;

        else return 0;}//ISFULL

void main(){

        const int MAXSTACKSIZE=5;

        int mystack[MAXSTACKSIZE];int mytop,x,option;

        mytop=0;//STACK TOP INITILIZATION

        do{cout<<"SELECT ONE OF THE FOLLOWING OPTIONS:"<<endl;

        cout<<"1-PUSH 2-POP 3-EMPTY 4-ISFULL 5-QUIT:";

        cin>>option;

        switch(option){

        case 1: if (isfull(mytop,MAXSTACKSIZE))

                                                        cout<<"YOU CANT PUSH"<<endl;

                        else{ cout<<"ENTER THE NUMBER THAT WILL BE PUSHED:";

                                                        cin>>x;

                                                        push(mystack,mytop,x);}//ELSE

                        break;

        case 2: if(isempty(mytop))

                                                        cout<<"YOU CANT POP"<<endl;

                        else{ cout<<"THE NUMBER POOPED IS:"<<pop(mystack,mytop);

                        cout<<endl;}//ELSE

                        break;

        case 3: if(isempty(mytop)==1)

                                                        cout<<"STACK EMPTY."<<endl;

                        else cout<<"STACK IS NOT EMPTY."<<endl;

                        break;

        case 4: if(isfull(mytop, MAXSTACKSIZE)==1)

                                                                        cout<<"STACK FULL."<<endl;

                        else cout<<"STACK IS NOT FULL."<<endl;

                        break;

        case 5: cout<<"THANK YOU FOR USING OUR MENU!"<<endl;

                        break;

        default:cout <<"ENTER CORRECT OPTIONS"<<endl;}//switch

        }while (option !=5);

}//MAIN

 



BACK TO THE MAIN MENU....






CLASS NOTES FOR 9/26/02

Stack = Last one first
ADT = abstract data type (user defined data type)
Info is hidden when things are abstract.

for (int i = 0, i < 6, i++)

cin >> table[i];

 

for (i=5,i >= 0 , i--)

 

  • Everything is a character (every strike on a keyboard is a character)

 

 

Assume the following:

 

23

char t;

cin.get (t)

cout <, t //will give u the value 2

 

 

 

void main()

{

int num;

char t;

cin.get(t)

if t(>=’0’) && (t<=’9’){

cin >> num;

cout << “number”;

else cout << “not number”;

 

// output = 3

 

 

ENTER A POSTFIX NOTATION

 

//ENTER A POSTFIX NOTATION

 

#include<iostream.h>

void push (int stack[],int &top,int x){

            stack[top++]=x; }//push

int pop (int stack [],int &top){

            return stack [--top]; }//pop

int evaluate(int num1, int num2, char t){

            switch(t){

            case'+':return num2+num1;break;

            case'-':return num2-num1;break;

            case'/':return num2/num1;break;

            case'*':return num2*num1;break;

            }//switch

}//evaluate

int main (){

            int stack [10],top=0,x,num1,num2,value;

            char t;

            cout<<"please enter a postfix notation"<<endl;

            while(cin.get(t)){

                        if((t>='0')&&(t<='9')){

                                    cin.putback(t);cin>>x;

                                    push(stack,top,x);}//if

                        else if ((t=='+') || (t=='-')||(t=='/')||(t=='*')){

                                    num1=pop(stack,top);

                                    num2=pop(stack,top);

                                    value=evaluate (num1,num2,t);

                                    push (stack,top,value);

                        }//else if

                        if (t=='\n') break;

            }//while

            cout<<pop(stack,top);

            return 0;

}//main

 

//OUTPUT IS 12 5 3 + *

 

 

Choice b is a better form of programming because it has structure to it.

 

Infix Evaluation

2 3 4 * +

Algorithm = If digit then PUSH

                                else

                                if operator

                                pop

                                pop

                                evaluate

                                push

                                else no more, pop

                                DISPLAY

 

How would make a stack?

Array

176 786 664

 

0 1 2 3

 

Stack

number [0] = 176

number [1] = 786

number [2] = 664

number [i]

                i++;

stack [i]

                i++;

 

change i to top

 

stack[top] = X

top++;

 

1)       1)       Write a function called Push?

Int stack [10];

Int top = 0;

Int x;

Push (){

Stack [top] = x

Top++;

}

main()

{

push();

}//main

 

2)       2)       2 ways to use stack are Array and Pointer

SIMPLE STACK MENU

 

#include<iostream.h>

void push (int mystack[],int & mytop,int item){

        mystack[mytop]=item;

        mytop=mytop+1;} //PUSH

int pop(int mystack[],int &mytop){

        mytop=mytop-1;

        int item=mystack[mytop];

        return item; }//POP

int isempty(int mytop){

        if(mytop==0) return 1;

        else return 0;}//ISEMPTY

int isfull(int mytop,const int MAXSTACKSIZE){

        if(mytop==MAXSTACKSIZE)return 1;

        else return 0;}//ISFULL

void main(){

        const int MAXSTACKSIZE=5;

        int mystack[MAXSTACKSIZE];int mytop,x,option;

        mytop=0;//STACK TOP INITILIZATION

        do{cout<<"SELECT ONE OF THE FOLLOWING OPTIONS:"<<endl;

        cout<<"1-PUSH 2-POP 3-EMPTY 4-ISFULL 5-QUIT:";

        cin>>option;

        switch(option){

        case 1: if (isfull(mytop,MAXSTACKSIZE))

                                                        cout<<"YOU CANT PUSH"<<endl;

                        else{ cout<<"ENTER THE NUMBER THAT WILL BE PUSHED:";

                                                        cin>>x;

                                                        push(mystack,mytop,x);}//ELSE

                        break;

        case 2: if(isempty(mytop))

                                                        cout<<"YOU CANT POP"<<endl;

                        else{ cout<<"THE NUMBER POOPED IS:"<<pop(mystack,mytop);

                        cout<<endl;}//ELSE

                        break;

        case 3: if(isempty(mytop)==1)

                                                        cout<<"STACK EMPTY."<<endl;

                        else cout<<"STACK IS NOT EMPTY."<<endl;

                        break;

        case 4: if(isfull(mytop, MAXSTACKSIZE)==1)

                                                                        cout<<"STACK FULL."<<endl;

                        else cout<<"STACK IS NOT FULL."<<endl;

                        break;

        case 5: cout<<"THANK YOU FOR USING OUR MENU!"<<endl;

                        break;

        default:cout <<"ENTER CORRECT OPTIONS"<<endl;}//switch

        }while (option !=5);

}//MAIN

 

BACK TO THE MAIN MENU....






CLASS NOTES FOR 10/22/02

Read Chapter 14 from "Easy Ways"
BACK TO THE MAIN MENU....






CLASS NOTES FOR 11/12/02

BACK TO THE MAIN MENU....







(This is the end of the page.)

1