..
Exercise 1
Write a program in C Language that implement 2 functions:
a) convertDoublyToCircular that takes in a doubly linked list and converts it into a circular list
b) convertCircularToStack that takes in a circular linked list and returns a stack with all the
nodes of the linked list on the stack
.
//////////////////////////////////////////////////
////
Exercise 2
Using only the given implementation of SinglyLinkedList class and Stack class add method into
SinglyLinkedList that received as a parameter another SinglyLinkedList and checks if the
received list is a subset of the current list and return either true or false based on the result. You must use the
given Stack implementation to perform this check.
Implementations :
1) Doubly LinkedList
2) Singly LinkedList
3) Stack
Will be given in another attachment.
//////////////////////////////////////////////////
Exercise 3
(Solve in C LANGUAGE) instead of c++
Using only std::queue do the following:
a. Write a recursive C++ method recursiveDisplayReverseOrder that takes as parameters a
Queue of strings, where each element is a word and display the words in reverse order.
b. Write a C++ method iterativeDisplayReverseOrder which behaves just like the method in
part a but doesn’t use recursion.
Note that std::queue has a slightly different way to access data. Function pop() will only remove the
first element from the queue without returning anything. To get the data you have to use function front()
then do pop() to remove it. For more details:
https://en.cppreference.com/w/cpp/container/queue
//////////////////////////////////////////////////////////
Exercise 4
Write a C program that implements a dequeue (double ended queue) abstract data type using 1) an unsorted
doubly linked list, and 2) using a sorted doubly linked list. You must use the DoublyLinkedList provided
to you with this assignment.
.
Example of how my C program syntaxes are like:
(please try to follow them as much as possible)
1)Linked Lists:
#include
#include
typedef struct Node
{
int data;
struct Node *next;
}
node;
node *head=NULL;
////// LINKED LISTS //////
void insertAtFirst(node **head,int x)
{
node *p;
p=(node*)malloc(sizeof(node));
p->data=x;
p->next=NULL;
if(*head==NUll)
*head=p;
else
{
p->next=(*head);
*head=p;
}
}/
/
void insertAtEnd(node **head,int x)
{
node *p,*q;
p=(node*)malloc(sizeof(node));
p->data=x;
p->next=NULL;
if(*head==NULL)
*head=p;
else
{
q=*head;
while(q->next!=NULL)
q=q->next;
q->next=p;
p->next=NULL;
}
}/
/
void deleteFrist(node **head)
{
node *p;
if(*head==NULL)
{
printf(“Linked List is Empty”);
return;
}
else
{
p=*head;
*head=(*head)->next;
free(p);
}
}//
void deleteLast(node **head)
{
node *p,*q;
if(*head==NULL)
{
printf(“Linked List is Empty”);
return;
}
else
{
q=*head;
p=(*head)->next;
while(p->next!=NULL)
{
p=p->next;
q=q->next;
}
q->next=NULL;
free(p);
}
}
2)Stacks:
#include
#include
typedef struct Node{
int data;
struct Node *next;
}stack;
stack *Top=NULL;
////// Stacks //////
void push(stack **Top,int x)
{
stack *p;
p=(stack*)malloc(sizeof(stack));
p->data=x;
p->next=NULL;
if(*Top==NULL)
*Top=p;
else
{
p->next=*Top;
*Top=p;
}
}//
int pop(stack **Top)
{
stack *p;
int x=-1;
if(*Top==NULL)
{
printf(“Stack is Empty\n”);
returnx;
}
else
{
p=*Top;
x=(*Top)->data;
*Top=(*Top)->next;
return x;
}
}//
void printStack(stack *Top)
{
stack *p;
for(p=Top;p!=NULL;p=p->next)
printf(“%d”,p->data);
}//
3)Queues:
#include
#include
typedef struct Node{
int data;
struct Node *next;
}Queue;
Queue *front=NULL;
Queue *rear=NULL;
////// Queues //////
void enqueue(Queue **front,Queue **rear,int x)
{
Queue *p;
p=(Queue*)malloc(sizeof(Queue));
p->data=x;
p->next=NULL;
if(*front==NULL)
*front=*rear=p;
else
{
(*rear)->next=p;
*rear=p;
}
}//
int dequeue(Queue **front,Queue **rear)
{
int x=-1;
Queue *p;
if(*front==NULL)
{
printf(“Queue is Empty.\n”);
return x;
}
else
{
x=(*front)->data;
p=(*front);
if( (*front)->next==NULL )
{
*front=*rear=NULL;
free(p);
return x;
}
else
{
*front=(*front)->next;
free(p);
}
}
}/
//Singly LinkedList
#include
#include
using namespace std;
class SinglyNode {
public:
int data;
SinglyNode *next;
SinglyNode(int d, SinglyNode *ptr = 0) {
data = d;
next = ptr;
}
};
class SinglyLinkedList {
public:
SinglyNode *head, *tail;
SinglyLinkedList() {
head = tail = 0;
}
~SinglyLinkedList() {
for(SinglyNode *p; !isEmpty();) {
p = head->next;
delete head;
head = p;
}
}
int isEmpty() {
return head == 0;
}
void addToBack(int data) {
if (tail != 0) {
tail->next = new SinglyNode(data);
tail = tail->next;
} else head = tail = new SinglyNode(data);
}
void addToFront(int data) {
/* to be implemented… */
}
int removeFromBack() {
/* to be implemented… */
return -1;
}
int removeFromFront() {
/* to be implemented… */
return -1;
}
bool isSubset(SinglyLinkedList& otherlist) {
/* to be implemented… */
return false;
}
int size() {
SinglyNode *p = head;
int counter=0;
while (p != 0) {
p = p->next;
counter++;
}
return counter;
}
void print() {
SinglyNode *p = head;
while (p != 0) {
cout << p->data << " ---> ” ;
p = p->next;
}
cout << "/\n\n" ;
}
};
int main() {
SinglyLinkedList list;
list.addToBack(100);
list.addToBack(5);
list.addToBack(20);
list.addToBack(33);
list.print();
return 0;
}
//Stack
#include
#include
using namespace std;
class StackNode {
private:
char data;
StackNode *next;
public :
StackNode(){
next=0;
}
StackNode(char n ,StackNode* ptr=0 ){
data =n ;
next= ptr;
}
friend class Stack;
};
class Stack
{
private:
StackNode *head,*tail;
public:
Stack() {
head=tail=0;
}
void push(char d){
head = new StackNode (d,head);
if (tail ==0)
tail = head ;
}
char pop (){
char d = head->data;
StackNode * temp = head;
if(head == tail )
head = tail = 0;
else
head = head->next;
delete temp;
return d;
}
bool isEmpty(){
if(head == 0)
return true;
else
return false;
}
};
int main(int argc, char *argv[]) {
Stack s;
s.push(‘m’);
s.push(‘o’);
s.push(‘c’);
s.push(‘l’);
s.push(‘e’);
s.push(‘W’);
while(!s.isEmpty()) {
cout << s.pop();
}
cout << endl ;
return 0;
}
//Doubly LinkedList
#include
#include
using namespace std;
class DoublyNode {
public:
int data;
DoublyNode *next;
DoublyNode *prev;
DoublyNode(int d, DoublyNode *ptr_n = 0, DoublyNode *ptr_p = 0) {
data = d;
next = ptr_n;
prev = ptr_p;
}
};
class DoublyLinkedList {
public:
DoublyNode *head, *tail;
DoublyLinkedList() {
head = tail = 0;
}
~DoublyLinkedList() {
for(DoublyNode *p; !isEmpty();) {
p = head->next;
delete head;
head = p;
}
}
int isEmpty() {
return head == 0;
}
void add(int data) {
if (tail != 0) {
tail->next = new DoublyNode(data, 0, tail);
tail = tail->next;
} else head = tail = new DoublyNode(data);
}
int size() {
DoublyNode *p = head;
int counter=0;
while (p != 0) {
p = p->next;
counter++;
}
return counter;
}
void print() {
DoublyNode *p = head;
while (p != 0) {
cout << p->data ;
if(p->next != 0)
cout << " <---> ” ;
p = p->next;
}
cout << "\n\n" ;
}
void printInReverse() {
DoublyNode *p = tail;
while (p != 0) {
cout << p->data;
if(p->prev != 0)
cout << " <---> ” ;
p = p->prev;
}
cout << "\n\n" ;
}
};
int main() {
DoublyLinkedList list;
int const size1=5;
int data1[size1];
list.add(100);
list.add(27);
list.add(13);
list.add(4);
list.print();
list.printInReverse();
return 0;
}
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.