SlideShare a Scribd company logo
Data Structure




Data Structure and File Management




           Course Work

              Mark Green


       Excelsior Community College


           Amis 2A (Evening)


             March 3, 2011
Question 1 Solution

#include <iostream.h>

#include <stdio.h>

#include <string.h>

#include<conio.h>

using namespace std;



class Stack {

private:

     char letters[50];

     int size;

public:



     Stack() {

         size = -1;

     }

     void push(char p);

     char pop();

     int getSize();

};



void Stack::push(char p) {

     if (size < 50) {

         letters[++size] = p;

     }
}



char Stack::pop() {

     if (size != -1) {

          return letters[size--];

     }

}



class Queue {

private:

     char letters[50];

     int size;

     int start;

public:



     Queue() {

          start = 0;

          size = 0;

     };

     void enqueue(char p);

     char Dequeue();

};



void Queue::enqueue(char p) {

     if (size < 50) {
letters[size] = p;

        size++;

    }

}



char Queue::Dequeue() {

    char value;

    if (start < size) {

        value = letters[start];

        start++;

        return value;

    }

}



int palindrome(char *word) {

    Stack stack;

    Queue queue;

    int check = 1; // this is a palindrome until proven that this is not the case

    int len = strlen(word);



    for (int i = 0; i < len; i++) {

        stack.push(word[i]);

        queue.enqueue(word[i]);

    }
// This condition perform the palindrome test

    char j,q;

    for (int i = 0; i < len / 2; i++) {

        char j = stack.pop();

        char s = queue.Dequeue();



        if (j != s) {

            check = 0;

        }



    }

    return check;

}



int main() {

    char words[60];

    cout << "Please Imput Data :";// The user is prompt to enter the data item

    gets(words);



    if (palindrome(words)) {

        cout << "Words is a palindrome t";

    } else {

        cout << "this is not a palindrome t";

    }

    system("pause");
return 0;

}

More Related Content

What's hot

Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
Lorenz Cuno Klopfenstein
 
Collection Core Concept
Collection Core ConceptCollection Core Concept
Collection Core Concept
Rays Technologies
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
njpst8
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
Sri Harsha Pamu
 
Networking Core Concept
Networking Core ConceptNetworking Core Concept
Networking Core Concept
Rays Technologies
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
領一 和泉田
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
Programs
ProgramsPrograms
Linq - an overview
Linq - an overviewLinq - an overview
Linq - an overviewneontapir
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 
Introduction to Go for Java Programmers
Introduction to Go for Java ProgrammersIntroduction to Go for Java Programmers
Introduction to Go for Java Programmers
Kalpa Pathum Welivitigoda
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)
Aaron Gustafson
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
Mahmoud Samir Fayed
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
Kevlin Henney
 

What's hot (20)

Introduzione a C#
Introduzione a C#Introduzione a C#
Introduzione a C#
 
C Prog - Array
C Prog - ArrayC Prog - Array
C Prog - Array
 
Collection Core Concept
Collection Core ConceptCollection Core Concept
Collection Core Concept
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
 
Lec23-CS110 Computational Engineering
Lec23-CS110 Computational EngineeringLec23-CS110 Computational Engineering
Lec23-CS110 Computational Engineering
 
Networking Core Concept
Networking Core ConceptNetworking Core Concept
Networking Core Concept
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Python легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачиPython легко и просто. Красиво решаем повседневные задачи
Python легко и просто. Красиво решаем повседневные задачи
 
Programs
ProgramsPrograms
Programs
 
Linq - an overview
Linq - an overviewLinq - an overview
Linq - an overview
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 
Introduction to Go for Java Programmers
Introduction to Go for Java ProgrammersIntroduction to Go for Java Programmers
Introduction to Go for Java Programmers
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
C programs
C programsC programs
C programs
 
The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)The Future of JavaScript (SXSW '07)
The Future of JavaScript (SXSW '07)
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 

Viewers also liked

Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3Bianca Teşilă
 
Mr. Palindrome
Mr. PalindromeMr. Palindrome
Mr. PalindromeKris Erice
 
Poscat seminar 8
Poscat seminar 8Poscat seminar 8
Poscat seminar 8
Hyungyu Shin
 
901230 lecture5&6
901230 lecture5&6901230 lecture5&6
901230 lecture5&6
Enad Almasri
 
Problem solving strategies in mathematics and computer science
Problem solving strategies in mathematics and computer scienceProblem solving strategies in mathematics and computer science
Problem solving strategies in mathematics and computer science
UT, San Antonio
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
vtunotesbysree
 
C and data structure
C and data structureC and data structure
C and data structure
prabhatjon
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
Aryan Ajmer
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
Saket Pathak
 
Data Structure with C
Data Structure with CData Structure with C
Data Structure with C
Syed Mustafa
 
Problem Solving Method
Problem Solving MethodProblem Solving Method
Problem Solving Method
Roxanne Deang
 
Palindrome number program in c
Palindrome number program in cPalindrome number program in c
Palindrome number program in c
mohdshanu
 

Viewers also liked (12)

Data structures and algorithms lab3
Data structures and algorithms lab3Data structures and algorithms lab3
Data structures and algorithms lab3
 
Mr. Palindrome
Mr. PalindromeMr. Palindrome
Mr. Palindrome
 
Poscat seminar 8
Poscat seminar 8Poscat seminar 8
Poscat seminar 8
 
901230 lecture5&6
901230 lecture5&6901230 lecture5&6
901230 lecture5&6
 
Problem solving strategies in mathematics and computer science
Problem solving strategies in mathematics and computer scienceProblem solving strategies in mathematics and computer science
Problem solving strategies in mathematics and computer science
 
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...VTU 1ST SEM  PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
VTU 1ST SEM PROGRAMMING IN C & DATA STRUCTURES SOLVED PAPERS OF JUNE-2015 & ...
 
C and data structure
C and data structureC and data structure
C and data structure
 
Programming flowcharts for C Language
Programming flowcharts for C LanguageProgramming flowcharts for C Language
Programming flowcharts for C Language
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Data Structure with C
Data Structure with CData Structure with C
Data Structure with C
 
Problem Solving Method
Problem Solving MethodProblem Solving Method
Problem Solving Method
 
Palindrome number program in c
Palindrome number program in cPalindrome number program in c
Palindrome number program in c
 

Similar to Data structure

I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
Ahad Butt
Ahad ButtAhad Butt
Ahad Butt
AhadButt
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
sudhirchourasia86
 
About java
About javaAbout java
About javaJay Xu
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
Samsil Arefin
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
sktambifortune
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
katherncarlyle
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
adityaraj7711
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
apexelectronices01
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
Xiaojun REN
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
11-ch04-3-strings.pdf
11-ch04-3-strings.pdf11-ch04-3-strings.pdf
11-ch04-3-strings.pdf
AndreaBatholomeo
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 

Similar to Data structure (20)

I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
Ahad Butt
Ahad ButtAhad Butt
Ahad Butt
 
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
  package Chapter_20;import ToolKit.PostfixNotation;import javaf.pdf
 
About java
About javaAbout java
About java
 
week-18x
week-18xweek-18x
week-18x
 
week-17x
week-17xweek-17x
week-17x
 
Program to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical orderProgram to sort the n names in an alphabetical order
Program to sort the n names in an alphabetical order
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
 
#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx#includeiostream#includecctypeusing namespace std;cl.docx
#includeiostream#includecctypeusing namespace std;cl.docx
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
Questions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdfQuestions has 4 parts.1st part Program to implement sorting algor.pdf
Questions has 4 parts.1st part Program to implement sorting algor.pdf
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
11-ch04-3-strings.pdf
11-ch04-3-strings.pdf11-ch04-3-strings.pdf
11-ch04-3-strings.pdf
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
C program
C programC program
C program
 

Data structure

  • 1. Data Structure Data Structure and File Management Course Work Mark Green Excelsior Community College Amis 2A (Evening) March 3, 2011
  • 2. Question 1 Solution #include <iostream.h> #include <stdio.h> #include <string.h> #include<conio.h> using namespace std; class Stack { private: char letters[50]; int size; public: Stack() { size = -1; } void push(char p); char pop(); int getSize(); }; void Stack::push(char p) { if (size < 50) { letters[++size] = p; }
  • 3. } char Stack::pop() { if (size != -1) { return letters[size--]; } } class Queue { private: char letters[50]; int size; int start; public: Queue() { start = 0; size = 0; }; void enqueue(char p); char Dequeue(); }; void Queue::enqueue(char p) { if (size < 50) {
  • 4. letters[size] = p; size++; } } char Queue::Dequeue() { char value; if (start < size) { value = letters[start]; start++; return value; } } int palindrome(char *word) { Stack stack; Queue queue; int check = 1; // this is a palindrome until proven that this is not the case int len = strlen(word); for (int i = 0; i < len; i++) { stack.push(word[i]); queue.enqueue(word[i]); }
  • 5. // This condition perform the palindrome test char j,q; for (int i = 0; i < len / 2; i++) { char j = stack.pop(); char s = queue.Dequeue(); if (j != s) { check = 0; } } return check; } int main() { char words[60]; cout << "Please Imput Data :";// The user is prompt to enter the data item gets(words); if (palindrome(words)) { cout << "Words is a palindrome t"; } else { cout << "this is not a palindrome t"; } system("pause");