This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 2.3 | |
* Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. | |
* EXAMPLE | |
* Input: the node c from the linked list a->b->c->d->e | |
* Result: nothing isreturned, but the new linked list looks like a->b->d->e | |
*/ | |
#include <iostream> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 2.4 | |
* Write code to partition a linked list around a value x, | |
* such that all nodes less than x come before all nodes greater than or equal to x. | |
*/ | |
#include <iostream> | |
#include <list> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 2.5 | |
* You have two numbers represented by a linked list, where each node contains a single digit. | |
* The digits are stored in reverse order, such that the Ts digit is at the head of the list. | |
* Write a function that adds the two numbers and returns the sum as a linked list. | |
* EXAMPLE | |
* Input:(7-> 1 -> 6) + (5 -> 9 -> 2).That is,617 + 295. | |
* Output: 2 -> 1 -> 9.That is, 912. | |
* FOLLOW UP | |
* Suppose the digits are stored in forward order. Repeat the above problem. EXAMPLE | |
* Input:(6 -> 1 -> 7) + (2 -> 9 -> 5).That is,617 + 295. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 2.6 | |
* Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop. | |
* DEFINITION | |
* Circular linked list: A (corrupt) linked list in which a node's next pointer points to an earlier node, | |
* so as to make a loop in the linked list. | |
* EXAMPLE | |
* Input:A ->B->C->D->E->C [the same C as earlier] | |
* Output:C | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 2.7 | |
* Implement a function to check if a linked list is a palindrome. | |
*/ | |
#include <iostream> | |
#include <list> | |
#include <stack> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 3.5 | |
* Implement a MyQueue class which implements a queue using two stacks. | |
*/ | |
#ifndef MYQUEUEBETA_H | |
#define MYQUEUEBETA_H | |
#include <iostream> | |
#include <stack> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 3.6 | |
* Write a program to sort a stack in ascending order (with biggest items on top). | |
* You may use at most one additional stack to hold items, but you may not copy the elements into any other | |
* data structure (such as an array).The stack supports the following operations: push, pop, peek, and isEmpty. | |
*/ | |
#include <iostream> | |
#include <stack> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 3.7 | |
* Create the data structure to mantain a animal shelter system | |
* and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat | |
*/ | |
#ifndef ANIMALQUEUE_H | |
#define ANIMALQUEUE_H | |
#include <iostream> | |
#include <string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 3.7 | |
* Create the data structure to mantain a animal shelter system | |
* and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat | |
*/ | |
#ifndef ANIMALQUEUESLN_H | |
#define ANIMALQUEUESLN_H | |
#include <iostream> | |
#include <string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CC150 3.4 | |
* Classic problem of the Towers of Hanoi | |
* http://en.wikipedia.org/wiki/Tower_of_Hanoi | |
*/ | |
#include <iostream> | |
#include <stack> | |
using namespace std; |