Upcoming SlideShare
×

# Data structure

343 views

Published on

Marketing

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
343
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
2
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Data structure

1. 1. Data StructureData Structure and File Management Course Work Mark Green Excelsior Community College Amis 2A (Evening) March 3, 2011
2. 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. 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. 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. 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");
6. 6. return 0;}