Q.1. Write a C program that determines whether a line entered by
a user is a palindrome or not. You must demonstrate it as an
application of stack (you may use linked list implementation
demonstrated in the class). Hint! Think of the basic property of a
stack i.e. LIFO (list-in-first-out).
Q.2. Write a charQueue header file containing all the function
headers of following functions:
1- initiateQueue—to initialize a queue 2- enqueue—to add a node at
the rear end of the queue 3- dequeue—to remove a node from the
front of the queue 4- printQueue—print a queue
and an implementation file implementing these functions for a Queue
of chars. Inside your main method, which should be part of your
tester file, read a sequence of chars one at a time. Terminate your
sequence if user enters the number 0. Remember the difference
between a char and an int!
Print the text user entered (that was stored in your Queue as a
series of characters) using a while loop. You should loop as long
as the Queue is not empty.
#include<stdio.h>
#include<string.h>
#define MAX 50
int top=-1;
char stack[MAX];
void push(char c)
{
if(top==MAX-1)
{
printf("overflow");
}
else
{
top++;
stack[top]=c;
}
}
void pop()
{
if(top==-1)
{
printf("underflow");
}
else
{
top--;
}
}
int main()
{
char str[50];
int i,front=0;
printf("enter the string:");
scanf(" %[^\n]s",str);
for(i=0;str[i]!='\0';i++)
{
push(str[i]);
}
for(i=0;i<(strlen(str))/2;i++)
{
if(stack[top]==str[i])
{
pop();
front++;
}
else
{
printf("not
palindrome"); //If not
equal break the loop no need to check other characters.
break;
}
}
if(front==strlen(str)/2)
{
printf("palindrome");
}
}
Explanation:
In this i used arrays to implement the stack.To check given string is palindrome or not ,it is enough to check the left half of the string with right half of the string.the top of the element in stack is compared with first element of the string like that we go ..
OUTPUT:


Q2.
Header File:
#include<stdio.h>
#define MAX 150
int front,rear;
char Q[MAX];
void initiateQueue() //To initialize the queue
{
front=-1;
rear=-1;
}
void Enque(char c) // inserting at rear end
{
if(rear==MAX-1)
{
printf("Overflow");
}
else
{
rear++;
Q[rear]=c;
if(rear==0)
{
front=0;
}
}
}
void Dequeue() //deleting at front end
{
if(front==-1||front>rear)
{
printf("Underflow");
}
else
{
printf("deleted
character:%c\n\n",Q[front]);
front++;
}
}
void printQueue() //Displaying elements
{ int i;
printf("Displaying queue elements:");
for(i=front;i<=rear;i++)
{
printf("%c",Q[i]);
}
}
Main.cpp
#include<stdio.h>
#include<string.h>
#include "charQueue.h"
int main()
{
char str[150];
int i=0;
initiateQueue();
printf("enter sequence of characters:\n");
while(1)
{
scanf("%c",&str[i]);
if(str[i]=='0')
{
break;
}
Enque(str[i]);
}
i=front;
while(i<=rear)
{
printf("%c",Q[i]);
i++;
}
printf("\n\n");
Dequeue();
printQueue();
}
OUTPUT:

I have done this code in Dev c++ IDE.
If any doubts comment below...
Q.1. Write a C program that determines whether a line entered by a user is a...
C PROGRAMMING -- Please use simple code QUESTION: - Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the queue 3- dequeue—to remove a node from the front of the queue 4- printQueue—print a queue and an implementation file implementing these functions for a Queue of chars. Inside your main method, which should be part of your tester file, read a...
C Programming -- please use simple coding Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out).
HI USING C++ CAN YOU PLEASE PROGRAM THIS ASSIGNMENT AND ADD
COMMENTS:
stackARRAY:
#include<iostream>
#define SIZE 100
#define NO_ELEMENT -999999
using namespace std;
class Stack {
int arr[SIZE]; // array to store Stack elements
int top;
public:
Stack() {
top = -1;
}
void push(int); // push an element into Stack
int pop(); // pop the top element from Stack
int topElement(); // get the top element
void display(); // display Stack elements from top to bottom
};
void Stack...
Write a C++ program to implement Queue ADT using singly linked structure. The program includes the following: Define the Queue class template in the header file QueueLinked.h. // QueueLinked.h #ifndef QUEUE_H #define QUEUE_H #include <iostream> using namespace std; template <typename T> class Queue { public: // Constructor Queue(); //Desctructor ~Queue(); // Makes the queue to the empty state. void make_empty(); // Checks if the queue is empty. bool empty() const; // Inserts item at the end of the queue. void...
Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use...
It is C++ problems, please explain your each line of code as
well.
Task 1: Implement/ Hard Code a Doubly Linked Lists and make it a Stack. Do not use ::list:: class from the STD library for this example. The user will input a string and the program will output the string backwards. Displaying correct Stack implementation. Utilize the conventional static methods as needed. push() pop() empty() peek() peek() Sample Execution Please input String: happy yppah Task 2: Implement /...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
help finish Queue, don't think
I have the right thing.
# 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...
Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...
C language: Write a program that uses a function to check if a user entered string is a palindrome. Based on the return value of the function, the results are printed in the main() function. (do not print results in function to check for palindrome) A palindrome reads the same forward as backward for example tacocat or civic.