Let's take a look how to set up a surrogate key.
CREATE TABLE Temp(
ID INT IDENTITY(1,2), -- it will go 1,3,5...
Name VARCHAR(100))
INSERT INTO Temp VALUES ('J-hood') -- no need to insert ID values
GO 5 -- insert 5 times
CREATE TABLE Temp(
ID INT IDENTITY(1,2), -- it will go 1,3,5...
Name VARCHAR(100))
INSERT INTO Temp VALUES ('J-hood') -- no need to insert ID values
GO 5 -- insert 5 times
-- Create Sales and Product tables CREATE TABLE Sale ( SaleID INT NOT NULL, ProductID INT NOT NULL, ClientID INT NOT NULL, Qty INT NOT NULL, Total MONEY) CREATE TABLE Product ( ProductID INT NOT NULL, ProdName VARCHAR(50), ProdDesc VARCHAR(100), QoH INT, UniPrice MONEY) -- Add a PK on Sale ALTER TABLE Sale ADD CONSTRAINT PK_Sale_SaleID PRIMARY KEY (SaleID) -- Dropping a PK ALTER TABLE Sale DROP CONSTRAINT PK_Sale_SaleID -- Add a composite PK ALTER TABLE Sale ADD CONSTRAINT PK_Sale_SaleID_ProductID PRIMARY KEY (SaleID, ProductID) -- Add a PK on Product ALTER TABLE Product ADD CONSTRAINT PK_Product_ProdID PRIMARY KEY (ProductID) -- Add a FK on Sale ALTER TABLE Sale ADD CONSTRAINT FK_Sale_Product_ProductID FOREIGN KEY (SaleID) REFERENCES Product(ProductID)
CREATE TABLE Sales2( SalesID INT NOT NULL PRIMARY KEY, ProductID INT REFERENCES Product(ProductID), ClientID INT REFERENCES Client(ClientID), Qty INT NOT NULL, Total MONEY)
CREATE TABLE Sales3(
SalesID INT NOT NULL
ProductID INT,
ClientID INT,
Qty INT NOT NULL CONSTRAINT DK_Sales3_Qty DEFAULT 10,
Total MONEY -- No comma here!!
CONSTRAINT PK_Sales3_SalesID PRIMARY KEY (SalesID)
CONSTRAINT FK_Sales3_Product_ProductID FOREIGN KEY (ProductID)
REFERENCES Product(ProductID)
CONSTRAINT FK_Sales3_Client_ClientID FOREIGN KEY (ClientID)
REFERENCES Client(ClientID)
CONSTRAINT CK_Sales3_Qty CHECK (Qty >= 10))
1-2 | | 3-4If you can only take right and bottom paths and cannot backtrack as the problem describes, there are only two ways to get to 4 (1 - 2 - 4 and 1 - 3 - 4).
1-2-3 | | | 4-5-6 | | | 7-8-9As the problem explains, there are six ways to get to 9 from 1.
1 - 2 - 3 - 6 - 9 1 - 2 - 5 - 6 - 9 1 - 2 - 5 - 8 - 9 1 - 4 - 5 - 6 - 9 1 - 4 - 5 - 8 - 9 1 - 4 - 7 - 8 - 9This isn't really a necessary step to find the solution but I redrew the 2 x 2 grid to a tree form, where you can only take down paths, so I could understand better.
1
/ \
2 3
/ \ / \
4 5 6
\ / \ /
7 8
\ /
9
Did the same for the 1 x 1 grid. 1
/ \
2 3
\ /
4
As you noticed, they form a diamond shape. Do the same thing for a 3 x 3 grid. Then you will find out that a 3 x 3 grid has 20 paths. So a 1 x 1 grid has 2 paths, a 2 x 2 grid has 6 paths and a 3 x 3 grid has 20 paths. This progression of 2, 6 and 20 were familiar to me and I found out that these numbers are related to Pascal's Triangle. 1 - 0th row
1 1
1(2)1 - 2nd row (1 by 1 grid)
1 3 3 1
1 4 (6) 4 1 - 4th row (2 by 2 grid)
1 5 10 10 5 1
1 6 15 (20) 15 6 1 - 6th row (3 by 3 grid)
So beginning from the 2nd row the going down every other row, the middle number of each row represents the number of paths. Here is the formula to find a certain number in Pascal's Triangle: 1
/ \
2 3
/ \ / \
4 5 6
\ / \ /
7 8
\ /
9
If you place this diamond on the Pascal's Triangle…1 / \ 1 1 / \ / \ 1 2 1 \ / \ / 3 3 \ / (6)Very interesting, isn't it?! But how the number of paths and Pascal's Triangle are related? I did some research and I found out that it's because Pascal's Triangle determines the coefficients which arise in binomial expansions and this grid problem is also very related to binomial expansions.
;;;;; ProjectEuler.net
;;;;; Problem 1 ~ 5
;;;;; Source code by J-hood
;;;;; Last updated on Feb-29-2011
;;;; Problem 1 ;;;;
;; If we list all the natural numbers below 10 that are multiples of 3 or 5,
;; we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all
;; the multiples of 3 or 5 below 1000.
;; Run: (problem1)
;; Answer: 233168
(defun problem1 ()
(let ((sum 0))
(dotimes (i 1000)
(if (OR (= 0 (mod i 3)) (= 0 (mod i 5)))
(setf sum (+ sum i))))
(print sum)))
;;;; Problem 2 ;;;;
;; Each new term in the Fibonacci sequence is generated by adding the previous
;; two terms. By starting with 1 and 2, the first 10 terms will be:
;; 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
;; By considering the terms in the Fibonacci sequence whose values do not exceed
;; four million, find the sum of the even-valued terms.
;; Run: (problem2)
;; Answer: 4613732
(defun problem2 ()
(let ((sum 0) (i 2))
(loop
(setf fibNum (fib i))
(incf i)
(when (> fibNum 4000000) (return))
(if (= 0 (mod fibNum 2))
(setf sum (+ sum fibNum))))
(print sum)))
(defun fib (n)
"Simple fibonacci number function"
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2)))))
;;;; Problem 3 ;;;;
;; The prime factors of 13195 are 5, 7, 13 and 29.
;; What is the largest prime factor of the number 600851475143 ?
;; Run: (problem3 600851475143 2)
;; Answer: 6857
(defun problem3 (n i)
(cond
((= (/ n i) 1) (print n))
((= 0 (mod n i)) (problem3 (/ n i) i))
(t (loop
(if (OR (= i 2) (= i 3) (/= i 4) (= i 5) (/= i 6) (= i 7))
(incf i)
(incf i 2))
(if (is-prime i) (return)))
(problem3 n i))))
(defun is-prime (n)
"Check if n is a prime number.
http://www.informatimago.com/develop/lisp/l99/p31.lisp"
(cond
((minusp n) (is-prime (- n)))
((= 1 n) nil)
((member n '(2 3 5 7)) t)
((evenp n) nil)
(t
(loop
:with root = (isqrt n)
:with divisors = (loop :for i :from 3 :to root :by 2 :collect i)
:for d = (pop divisors)
:if (zerop (mod n d))
:do (return nil)
:else :do (setf divisors (delete-if (lambda (x) (zerop (mod x d))) divisors))
:while divisors
:finally (return t)))))
;;;; Problem 4 ;;;;
;; A palindromic number reads the same both ways. The largest palindrome made
;; from the product of two 2-digit numbers is 9009 = 91 * 99. Find the largest
;; palindrome made from the product of two 3-digit numbers.
;; Run: (problem4)
;; Answer: 906609
(defun problem4 ()
(let ((result 0))
(loop for num1 from 999 downto 100 do
(loop for num2 from 999 downto num1 do
(if (>= result (* num1 num2))
(return))
(if (check-palindrome(* num1 num2))
(setf result (* num1 num2)))))
result))
(defun check-palindrome (n)
"Check the number is palindrome."
(let ((num-list (number-to-list n)))
(if (equalp num-list (reverse num-list))
(progn
(print num-list)
t)
nil)))
(defun number-to-list (number)
"Coerce numbers to lists."
(assert (and (integerp number)
(>= number 0)))
(labels ((number-to-list/recursive (number)
(cond
((zerop number)
nil)
(t
(cons (mod number 10)
(number-to-list/recursive (truncate (/ number 10))))))))
(nreverse (number-to-list/recursive number))))
;;;; Problem 5 ;;;;
;; 2520 is the smallest number that can be divided by each of the numbers from
;; 1 to 10 without any remainder. What is the smallest positive number that is
;; evenly divisible by all of the numbers from 1 to 20?
;; Run: (problem5 0)
;; Answer: 232792560
(defun problem5 (n)
(cond
((= n 0) (problem5 (+ 20 n)))
(t
(let ((isItDivisible t))
(dotimes (i 20)
(if (null (= (mod n (1+ i)) 0))
(progn
(setf isItDivisible nil)
(return))))
(if (eql isItDivisible t)
(print n)
(problem5 (+ 20 n)))))))
#import <UIKit/UIKit.h>
@interface CalculatorViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *display;
@end
#import "CalculatorViewController.h"
#import "CalculatorBrain.h"
@interface CalculatorViewController()
@property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
@property (nonatomic) BOOL thereIsADot;
@property (nonatomic, strong) CalculatorBrain *brain;
@property (weak, nonatomic) IBOutlet UILabel *dictionaryDisplay;
@property (weak, nonatomic) IBOutlet UILabel *variableDisplay;
@property (strong, nonatomic) NSArray *valueArray;
@property (weak, nonatomic) IBOutlet UILabel *infixDisplay;
@end
@implementation CalculatorViewController
@synthesize display;
@synthesize variableDisplay;
@synthesize dictionaryDisplay;
@synthesize userIsInTheMiddleOfEnteringANumber;
@synthesize thereIsADot;
@synthesize brain = _brain;
@synthesize valueArray = _valueArray;
@synthesize infixDisplay;
- (CalculatorBrain *)brain
{
if (!_brain) _brain = [[CalculatorBrain alloc] init];
return _brain;
}
- (NSArray *)valueArray
{
if (!_valueArray)
_valueArray = [NSArray arrayWithObjects: [NSNumber numberWithInt:0],
[NSNumber numberWithInt:0],
[NSNumber numberWithInt:0], nil];
return _valueArray;
}
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = [sender currentTitle];
if (self.userIsInTheMiddleOfEnteringANumber) {
if (self.thereIsADot) {
if ([digit isEqualToString:@"."]) {
// do nothing
}
else
self.display.text = [self.display.text stringByAppendingString:digit];
} else {
if ([digit isEqualToString:@"."]) {
self.thereIsADot = YES;
self.display.text = [self.display.text stringByAppendingString:digit];
} else
self.display.text = [self.display.text stringByAppendingString:digit];
}
} else {
if ([digit isEqualToString:@"."])
self.thereIsADot = YES;
self.display.text = digit;
self.userIsInTheMiddleOfEnteringANumber = YES;
}
}
- (IBAction)enterPressed
{
[self.brain pushOperand:[self.display.text doubleValue]];
self.userIsInTheMiddleOfEnteringANumber = NO;
self.thereIsADot = NO;
}
- (IBAction)operandPressed:(id)sender
{
if (self.userIsInTheMiddleOfEnteringANumber) {
[self enterPressed];
}
NSString *operation = [sender currentTitle];
double result = [self.brain performOperation:operation];
self.display.text = [NSString stringWithFormat:@"%g", result];
[infixDisplay setText:[CalculatorBrain descriptionOfProgram:self.brain.program]];
}
- (IBAction)CPressed
{
self.display.text = @"0";
self.userIsInTheMiddleOfEnteringANumber = NO;
self.thereIsADot = NO;
self.variableDisplay.text = @"";
self.infixDisplay.text = @"";
[self.brain emptyStack];
_brain = [[CalculatorBrain alloc] init];
}
- (IBAction)plusMinusPressed:(UIButton *)sender
{
if (userIsInTheMiddleOfEnteringANumber) {
NSString *newString;
double number = [self.display.text doubleValue];
if (number > 0) {
number = -number;
newString = [NSString stringWithFormat:@"%g",number];
self.display.text = newString;
} else if (number < 0) {
number = abs(number);
newString = [NSString stringWithFormat:@"%g",number];
self.display.text = newString;
}
}
else {
NSString *operation = [sender currentTitle];
double result = [self.brain performOperation:operation];
self.display.text = [NSString stringWithFormat:@"%g", result];
}
}
- (IBAction)testPressed:(UIButton *)sender
{
self.variableDisplay.text = @"";
NSString *testNumber = [sender currentTitle];
NSNumber *value1, *value2, *value3;
if ([testNumber isEqualToString:@"Test 1"]) {
value1 = [NSNumber numberWithInt:3];
value2 = [NSNumber numberWithInt:4];
value3 = [NSNumber numberWithInt:0];
} else if ([testNumber isEqualToString:@"Test 2"]) {
value1 = [NSNumber numberWithInt:0];
value2 = [NSNumber numberWithInt:-4];
value3 = [NSNumber numberWithInt:-10];
} else if ([testNumber isEqualToString:@"Test 3"]) {
value1 = [NSNumber numberWithInt:10];
value2 = [NSNumber numberWithInt:0];
value3 = [NSNumber numberWithInt:100];
}
_valueArray = [NSArray arrayWithObjects: value1, value2, value3, nil];
}
- (IBAction)variablePressed:(UIButton *)sender
{
NSString *variable = [sender currentTitle];
NSNumber *value;
if ([variable isEqualToString:@"x"]) {
value = [self.valueArray objectAtIndex:0];
} else if ([variable isEqualToString:@"a"]) {
value = [self.valueArray objectAtIndex:1];
} else if ([variable isEqualToString:@"b"]) {
value = [self.valueArray objectAtIndex:2];
}
[self.brain acceptVariables:variable AndItsValue:value];
NSMutableSet *variableDisplaySet = [[NSMutableSet alloc] init];
NSSet *variableSet = [self.brain returnVariableSet:[self.brain program]];
NSDictionary *variableDictionary = [self.brain variableDictionary];
double xValue, aValue, bValue = 0;
if ([variableSet containsObject:@"x"]) {
xValue = [[variableDictionary valueForKey:@"x"] doubleValue];
if (xValue != 0)
[variableDisplaySet addObject:[NSString stringWithFormat:@"x = %g ", xValue]];
}
if ([variableSet containsObject:@"a"]) {
aValue = [[variableDictionary valueForKey:@"a"] doubleValue];
if (aValue != 0)
[variableDisplaySet addObject:[NSString stringWithFormat:@"a = %g ", aValue]];
}
if ([variableSet containsObject:@"b"]) {
bValue = [[variableDictionary valueForKey:@"b"] doubleValue];
if (bValue != 0)
[variableDisplaySet addObject:[NSString stringWithFormat:@"b = %g ", bValue]];
}
NSString *newString = @"";
for (id obj in variableDisplaySet) {
if ([obj isKindOfClass:[NSString class]])
newString = [newString stringByAppendingFormat:obj];
}
self.variableDisplay.text = newString;
}
- (IBAction)undoPressed
{
if (userIsInTheMiddleOfEnteringANumber) {
if (self.display.text.length == 0)
userIsInTheMiddleOfEnteringANumber = NO;
else
self.display.text = [self.display.text substringToIndex:self.display.text.length - 1];
}
else {
do {
[self.brain popTheTopOfTheStack];
} while ([[self.brain getTheTopOfTheStack] isKindOfClass:[NSNumber class]] ||
[[self.brain getTheTopOfTheStack] isEqualToString:@"x"] ||
[[self.brain getTheTopOfTheStack] isEqualToString:@"a"] ||
[[self.brain getTheTopOfTheStack] isEqualToString:@"b"]);
if ([self.brain getTheTopOfTheStack])
self.display.text = [NSString stringWithFormat:@"%g", [CalculatorBrain runProgram:self.brain.program usingVariableValues:self.brain.variableDictionary]];
else
self.display.text = nil;
}
}
@end
@interface CalculatorBrain : NSObject
- (void)emptyStack;
- (NSSet *)returnVariableSet:(id)program;
- (void)popTheTopOfTheStack;
- (id)getTheTopOfTheStack;
- (void)pushOperand:(double)operand;
- (double)performOperation:(NSString *)op;
- (void)acceptVariables:(NSString *)variable
AndItsValue:(NSNumber *)value;
@property (nonatomic, readonly) id program;
@property (nonatomic, strong) NSMutableDictionary *variableDictionary;
+ (double)runProgram:(id)program
usingVariableValues:(NSDictionary *)variableValues;
+ (NSSet *)variablesUsedInProgram:(id)program;
+ (NSString *)descriptionOfProgram:(id)program;
@end
#import "CalculatorBrain.h"
@interface CalculatorBrain()
@property (nonatomic, strong) NSMutableArray *programStack;
@end
@implementation CalculatorBrain
@synthesize programStack = _programStack;
@synthesize variableDictionary = _variableDictionary;
- (NSMutableArray *)programStack
{
if (!_programStack) _programStack = [[NSMutableArray alloc] init];
return _programStack;
}
- (NSMutableDictionary *)variableDictionary
{
if (!_variableDictionary) _variableDictionary = [[NSMutableDictionary alloc] init];
return _variableDictionary;
}
- (id)program
{
return [self.programStack copy];
}
- (void)pushOperand:(double)operand
{
[self.programStack addObject:[NSNumber numberWithDouble:operand]];
}
- (void)acceptVariables:(NSString *)variable
AndItsValue:(NSNumber *)value
{
[self.variableDictionary setObject:value forKey:variable];
[self.programStack addObject:variable];
}
- (double)performOperation:(NSString *)operation
{
NSDictionary *dictionary = [self.variableDictionary copy];
[self.programStack addObject:operation];
return [[self class] runProgram:self.program usingVariableValues:dictionary];
}
+ (double)popOperandOffProgramStack:(NSMutableArray *)stack
{
double result = 0;
id topOfStack = [stack lastObject];
if (topOfStack) [stack removeLastObject];
if ([topOfStack isKindOfClass:[NSNumber class]]) {
result = [topOfStack doubleValue];
}
else if ([topOfStack isKindOfClass:[NSString class]]) {
NSString *operation = topOfStack;
if ([operation isEqualToString:@"+"]) {
result = [self popOperandOffProgramStack:stack] + [self popOperandOffProgramStack:stack];
} else if ([@"*" isEqualToString:operation]) {
result = [self popOperandOffProgramStack:stack] * [self popOperandOffProgramStack:stack];
} else if ([operation isEqualToString:@"-"]) {
double subtrahend = [self popOperandOffProgramStack:stack];
result = [self popOperandOffProgramStack:stack] - subtrahend;
} else if ([operation isEqualToString:@"/"]) {
double divisor = [self popOperandOffProgramStack:stack];
if (divisor) result = [self popOperandOffProgramStack:stack] / divisor;
} else if ([operation isEqualToString:@"sin"]) {
result = sin([self popOperandOffProgramStack:stack]);
} else if ([operation isEqualToString:@"cos"]) {
result = cos([self popOperandOffProgramStack:stack]);
} else if ([operation isEqualToString:@"sqrt"]) {
result = sqrt([self popOperandOffProgramStack:stack]);
} else if ([operation isEqualToString:@"pi"]) {
result = M_PI;
} else if ([operation isEqualToString:@"e"]) {
result = M_E;
} else if ([operation isEqualToString:@"log"]) {
result = log10([self popOperandOffProgramStack:stack]);
} else if ([operation isEqualToString:@"+/-"]) {
result = [self popOperandOffProgramStack:stack];
if (result > 0) result = -result;
else if (result < 0) result = abs(result);
}
}
return result;
}
+ (double)runProgram:(id)program
usingVariableValues:(NSDictionary *)variableValues
{
NSMutableArray *stack;
NSSet *variableSet = [self variablesUsedInProgram:program];
if ([program isKindOfClass:[NSArray class]])
stack = [program mutableCopy];
for (int i = 0; i < [stack count] - 1; i++) {
id object = [stack objectAtIndex:i];
if ([object isKindOfClass:[NSString class]]) {
if ([variableSet containsObject:object]) {
if ([object isEqualToString:@"x"])
[stack replaceObjectAtIndex:i withObject:[variableValues valueForKey:object]];
else if ([object isEqualToString:@"a"])
[stack replaceObjectAtIndex:i withObject:[variableValues valueForKey:object]];
else if ([object isEqualToString:@"b"])
[stack replaceObjectAtIndex:i withObject:[variableValues valueForKey:object]];
}
}
}
return [self popOperandOffProgramStack:stack];
}
+ (NSString *)descriptionOfProgram:(id)program
{
NSMutableArray *stack;
if ([program isKindOfClass:[NSArray class]]) {
stack = [program mutableCopy];
}
NSString *description = [self descriptionOfTopOfStack:stack];
if ([self isEnclosedByParentheses:description]) {
NSRange range;
range.location = 1;
range.length = [description length] - 2;
description = [description substringWithRange:range];
}
return description;
}
+ (NSString *)descriptionOfTopOfStack:(NSMutableArray *)stack
{
NSString *description;
id top = [stack lastObject];
if (top) {
[stack removeLastObject];
if ([top isKindOfClass:[NSNumber class]]) {
description = [top stringValue];
} else if ([top isKindOfClass:[NSString class]]) {
NSString *op = top;
if ([self is2OperandOperation:op]) {
NSString *secondOperand = [self descriptionOfTopOfStack:stack];
if ([secondOperand length] == 0) {
secondOperand = [NSString stringWithString:@"0"];
}
NSString *format = @"(%@ %@ %@)";
if ([self isMultiplicationOrDivision:op]) {
format = @"%@ %@ %@";
}
NSString *firstOperand = [self descriptionOfTopOfStack:stack];
if ([firstOperand length] == 0) {
firstOperand = [NSString stringWithString:@"0"];
}
description = [NSString stringWithFormat:format, firstOperand, op, secondOperand];
NSLog(@"%@", description);
} else if ([self is1OperandOperation:op]) {
NSString *topDescription = [self descriptionOfTopOfStack:stack];
if ([topDescription length] == 0) {
topDescription = [NSString stringWithString:@"0"];
}
NSString *format = @"%@(%@)";
if ([self isEnclosedByParentheses:topDescription]) {
format = @"%@%@";
}
if ([@"+/-" isEqualToString:op]) {
op = @"-";
}
description = [NSString stringWithFormat:format, op, topDescription];
} else if ([self is0OperandOperation:op] || [self isVariable:op]) {
description = op;
}
}
}
return description;
}
+ (BOOL)isEnclosedByParentheses:(NSString *)description
{
return ([@"(" isEqualToString:[description substringToIndex:1]] && [@")" isEqualToString:[description substringFromIndex:([description length] - 1)]]);
}
+ (BOOL)is2OperandOperation:(NSString *)operation
{
return [[self twoOperandOperators] containsObject:operation];
}
+ (BOOL)is1OperandOperation:(NSString *)operation
{
return [[self oneOperandOperators] containsObject:operation];
}
+ (BOOL)is0OperandOperation:(NSString *)operation
{
return [[self zeroOperandOperators] containsObject:operation];
}
+ (BOOL)isMultiplicationOrDivision:(NSString *)op
{
return [[self multiplicationAndDivision] containsObject:op];
}
+ (NSSet *)multiplicationAndDivision
{
return [NSSet setWithObjects:@"*", @"/", nil];
}
+ (NSSet *)twoOperandOperators
{
NSMutableSet *mutableSet = [[self multiplicationAndDivision] mutableCopy];
[mutableSet unionSet:[NSSet setWithObjects:@"+", @"-", nil]];
return mutableSet;
}
+ (NSSet *)oneOperandOperators
{
return [NSSet setWithObjects:@"sin", @"cos", @"sqrt", @"log", @"+/-", nil];
}
+ (NSSet *)zeroOperandOperators
{
return [NSSet setWithObjects:@"pi", @"e", nil];
}
+ (BOOL)isVariable:(NSString *)variable
{
NSSet *VARIABLES = [NSSet setWithObjects:@"a", @"b", @"x", nil];
return [VARIABLES containsObject:variable];
}
+ (NSSet *)variablesUsedInProgram:(id)program
{
NSMutableArray *stack;
NSMutableSet *variableMutableSet = [[NSMutableSet alloc] init];
if ([program isKindOfClass:[NSArray class]])
stack = [program mutableCopy];
for (id object in stack) {
if ([object isKindOfClass:[NSString class]])
if ([object isEqualToString:@"x"])
[variableMutableSet addObject:object];
else if ([object isEqualToString:@"a"])
[variableMutableSet addObject:object];
else if ([object isEqualToString:@"b"])
[variableMutableSet addObject:object];
}
NSSet *variableSet = [variableMutableSet copy];
return variableSet;
}
- (NSSet *)returnVariableSet:(id)program
{
NSSet *returnSet = [[self class] variablesUsedInProgram:(id)program];
return returnSet;
}
- (void)popTheTopOfTheStack
{
[self.programStack removeLastObject];
}
- (id)getTheTopOfTheStack
{
return [self.programStack lastObject];
}
- (void)emptyStack
{
_programStack = [[NSMutableArray alloc] init];
}
@end

newNode.next = node2;
newNode.prev = node1;
node1.next = newNode;
node2.prev = newNode;