diff --git a/.project b/.project deleted file mode 100644 index f4a67fb..0000000 --- a/.project +++ /dev/null @@ -1,11 +0,0 @@ - - - AlgorithmImplementations - - - - - - - - diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 67f336e..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2015 Minhas Kamal - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 23cbe13..0000000 --- a/README.md +++ /dev/null @@ -1,110 +0,0 @@ -# Algorithm Implementations -#### Implementation of Elementary Algorithms - -The project contains algorithms that were implemented in my Data Structure & Algorithms course. Yes, I got marks for those. :P - -### Categorical List of Algorithms - -AlgorithmImplementations
- ├─ arithmeticExpressions
- │ ├─ InfixEvaluation
- │ ├─ InfixToPostfix
- │ ├─ InfixToPrefix
- │ ├─ PostfixEvaluation
- │ └─ PrefixEvaluation
- ├─ dataStructures
- │ ├─ listImplementation
- │ │ ├─ implementationUsingNode
- │ │ │ ├─ OneWayLinkedList
- │ │ │ └─ TwoWayLinkedList
- │ │ ├─ OneWayLinkedList
- │ │ └─ TwoWayLinkedList
- │ ├─ stack
- │ │ ├─ StackImplementation
- │ │ └─ StackImplementation
- │ ├─ string
- │ │ ├─ String
- │ │ ├─ StringLongestCommonSubSecuence
- │ │ └─ StringLongestIncreasingSubSecuence
- │ └─ tree
- │   ├─ ActivitySelection
- │   ├─ BalanceTree
- │   ├─ KdTree
- │   ├─ BinaryHeap
- │   └─ BinomialTree
- ├─ graph
- │ ├─ BreathFirstSearch
- │ ├─ DepthFirstSearch
- │ ├─ MaxFlow
- │ ├─ ShortestPathAlgorithm
- │ └─ TopologicalSort
- ├─ numericalMethods
- │ ├─ calculus
- │ │ ├─ DerivetivesOnDifferentPoints
- │ │ ├─ IntegrationForwardInterpolation
- │ │ ├─ IntegrationSimpsonRule
- │ │ └─ IntersectingArea
- │ └─ equationSolving
- │   ├─ LinearEquationSolvingProcess
- │   │ ├─ JacobisMethod
- │   │ └─ GaussSeidalMethod
- │   └─ NonLinearEquationSolvingProcess
- │     ├─ BisectionMethod
- │     ├─ FalsePosition
- │     ├─ NewtonRaphson
- │     ├─ FixedPoint
- │     └─ Secant
- ├─ others
- │ ├─ cigaretteSmokersProblem
- │ ├─ geneticAlgorithm
- │ └─ huffmanAlgorithm (¿) (~)
- ├─ search
- │ ├─ AStarSearch
- │ ├─ BinarySearch
- │ └─ KnuthMorrisPrattAlgorithm
- ├─ sort
- │ └─ QuickSort
- ├─ thread
- │ ├─ priorityBased
- │ │ ├─ nonpreemptive
- │ │ └─ preemptive
- │ └─ shortestJob
- │   ├─ nonpreemptive
- │   └─ preemptive
- └─ playWithNumbers
-   ├─ factorial
-   │ ├─ BigFactorials
-   │ ├─ DigitsOfFactorial
-   │ └─ FactorsOfFactorial
-   ├─ fibonaciiNumber
-   │ ├─ FibonaciiNumber
-   │ ├─ FibonaciiSerise
-   │ └─ FibonaciiSum
-   ├─ otherNumbers
-   │ ├─ FriendNumbers
-   │ └─ PerfectNumberHaunting
-   ├─ pascalTriangle
-   │ ├─ BetterPascalTriangle
-   │ ├─ EasyPascalTriangle
-   │ ├─ PascalTriangle
-   │ ├─ Piramid
-   │ └─ RealPascalTriangle
-   ├─ primeNumber (Scrt Chmbr)
-   │ ├─ AnotherWayOfPrimeNumberHaunting
-   │ ├─ DefinitePrimeNumberHaunting
-   │ ├─ Factors
-   │ ├─ GreatPrimeNumberHaunting
-   │ ├─ GreatestPrimeNumberHaunting
-   │ ├─ PrimeNumber
-   │ ├─ PrimeNumberHaunting
-   │ └─ PrimeNumberHaunting
-   └─ time
-     ├─ AgeCalculator
-     ├─ LeapYearCounter
-     ├─ Stopwatch
-     └─ TimeAfter
- - -### License -MIT License
Algorithm Implementations is licensed under MIT License. - diff --git a/arithmeticExpressions/infixEvaluation/InfixEvaluation.cpp b/arithmeticExpressions/infixEvaluation/InfixEvaluation.cpp deleted file mode 100644 index c94c614..0000000 --- a/arithmeticExpressions/infixEvaluation/InfixEvaluation.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/** -Name: Minhas Kamal (minhaskamal024@gmail.com) -Description: This program reads an infix notation from a file & finds the result. -Date: Oct-2013 -**/ - -#include -#include -#include -#include -#include - -using namespace std; - - -double stringToDouble(string str); //converts a string to a double -int operatorPrecedence(char operat); //returns bigger integer depending on the precedence -double operation(double a, double b, char operat); //returns a result depending on the operator - - -struct element{ - string str; //string property - double value; //value of the string - bool opert; //operator-true, operand-false -}; - -int main(){ - ifstream input; //the input file - - input.open("InfixEvaluation_Input.txt"); - if(!input.is_open()){ //when file is not found exit - cout << "File name is wrong!\n"; - return 0; - } - - string s; //stores the input file's element as string - vector inputElement; //holds the behaviour of the input elements - while(input >> s){ //the loop determines the behaviour of the input elements - element elem; - elem.str = s; - - if(s[0]=='+' || s[0]=='-' || s[0]=='*' || s[0]=='/' || s[0]=='^' - || s[0]=='(' || s[0]==')'){ //when an operator is found - elem.value = -0.0; - elem.opert = true; - } - else{ - elem.value = stringToDouble(s); //this method converts string to double - elem.opert = false; - } - - inputElement.push_back(elem); - } - - input.close(); //closing the stream - - /*cout << "string \toperat \tvalue \n"; //output of the inputElement - for(int i=0; i operand; //postfix form of the input - stack operat; //temporarily stores operators - - operat.push('('); //pushing '(' at the beginning of stack - - bool everyThingOkFlag=true; - - for(int i=0; !operat.empty(); i++){ //evaluation - if(!inputElement[i].opert){ - operand.push(inputElement[i].value); - } - else{ - if(inputElement[i].str[0]=='('){ - operat.push('('); - } - else if(inputElement[i].str[0]==')'){ - while(operat.top()!='('){ - double b = operand.top(); //taking first two elements of the stack - operand.pop(); - double a = operand.top(); - operand.pop(); - - char oprt = operat.top(); //taking the top the operator of stack - operat.pop(); - - double result = 0; //result after the operation of a & b - result = operation(a, b, oprt); - - operand.push(result); //pushing the result in the operand stack - } - operat.pop(); //pops the '(' - } - else{ - int opertPrecedence = operatorPrecedence(inputElement[i].str[0]); - - while(operat.top()!='('){ - int stackPrecedence = operatorPrecedence(operat.top()); - - if(stackPrecedence < opertPrecedence) break; - else{ - double b = operand.top(); //taking first two elements of the stack - operand.pop(); - double a = operand.top(); - operand.pop(); - - char oprt = operat.top(); //taking the top the operator of stack - operat.pop(); - - double result = 0; //result after the operation of a & b - result = operation(a, b, oprt); - - operand.push(result); //pushing the result in the operand stack - } - } - operat.push(inputElement[i].str[0]); - } - } - - if(i>inputElement.size()) { - cout << "Math error! \n"; - everyThingOkFlag=false; - break; - } - } - - if(everyThingOkFlag) cout << "The result is: " << operand.top() << endl; - - return 0; -} - - -double stringToDouble(string str){ //converts a string to a double - double value=0, //holds the value of the string - afterPoint=0; //holds the value after a point - - bool flag = false; //represents if any point is found in the string - int numberOfElementAfterPoint=0; - - for(int i=0; str[i]!=NULL; i++){ - if(str[i]=='.') flag = true; //waiting for a '.' - else{ - if(flag){ - afterPoint = afterPoint*10 + (str[i]-48); - numberOfElementAfterPoint++; - } - else - value = value*10 + (str[i]-48); - } - } - - int divisor=1; //divides the afterPoint element by precise number of 10s - for(int i=0; i -#include -#include -#include -#include -using namespace std; - - -double stringToDouble(string str); -int operatorPrecedence(string str); -struct element{ - string str; //string property - double value; //value of the string - bool opert; //operator-true, operand-false -}; - -int main(){ - ifstream input; //the input file - - input.open("InfixToPostfix_Input.txt"); - if(!input.is_open()){ //when file is not found exit - cout << "File name is wrong!\n"; - return 0; - } - - string s; //stores the input file's element as string - vector inputElement; //holds the behaviour of the input elements - while(input >> s){ //the loop determines the behaviour of the input elements - element elem; - elem.str = s; - - if(s[0]=='+' || s[0]=='-' || s[0]=='*' || s[0]=='/' || s[0]=='^' || s[0]=='(' || s[0]==')'){ //when an operator is found - elem.value = -0.0; - elem.opert = true; - } - else{ - elem.value = stringToDouble(s); //this method converts string to double - elem.opert = false; - } - - inputElement.push_back(elem); - } - - input.close(); //closing the stream - - /*cout << "string \toperat \tvalue \n"; //output of the inputElement - for(int i=0; i postfix; //postfix form of the input - stack tempOpertStore; //temporarily stores operators - - tempOpertStore.push("("); - for(int i=0; !tempOpertStore.empty(); i++){ //conversion - if(!inputElement[i].opert){ - postfix.push_back(inputElement[i].str); - } - else{ - if(inputElement[i].str[0]=='('){ - tempOpertStore.push(inputElement[i].str); - } - else if(inputElement[i].str[0]==')'){ - while(tempOpertStore.top()[0]!='('){ - postfix.push_back(tempOpertStore.top()); - tempOpertStore.pop(); - } - tempOpertStore.pop(); //pops the '(' - } - else{ - int opertPrecedence = operatorPrecedence(inputElement[i].str); - - while(tempOpertStore.top()[0]!='('){ - int stackPrecedence = operatorPrecedence(tempOpertStore.top()); - - if(stackPrecedence < opertPrecedence) break; - else{ - postfix.push_back(tempOpertStore.top()); - tempOpertStore.pop(); - } - } - tempOpertStore.push(inputElement[i].str); - } - } - - /*cout << "after " << inputElement[i].str << ": "; //analysing every step - for(int j=0; j -#include -#include -#include -#include -using namespace std; - - -double stringToDouble(string str); -int operatorPrecedence(string str); -struct element{ - string str; //string property - double value; //value of the string - bool opert; //operator-true, operand-false -}; - -int main(){ - ifstream input; //the input file - - input.open("InfixToPrefix_Input.txt"); - if(!input.is_open()){ //when file is not found exit - cout << "File name is wrong!\n"; - return 0; - } - - string s; //stores the input file's element as string - vector inputElement; //holds the behaviour of the input elements - - element e; //pushing '(' at the start of the input representing the start - e.str = "("; - e.opert = true; - e.value = -0.0; - inputElement.push_back(e); - - while(input >> s){ //the loop determines the behaviour of the input elements - element elem; - elem.str = s; - - if(s[0]=='+' || s[0]=='-' || s[0]=='*' || s[0]=='/' || s[0]=='^' || s[0]=='(' || s[0]==')'){ //when an operator is found - elem.value = -0.0; - elem.opert = true; - } - else{ - elem.value = stringToDouble(s); //this method converts string to double - elem.opert = false; - } - - inputElement.push_back(elem); - } - - input.close(); //closing the stream - - /*/cout << "string \toperat \tvalue \n"; //output of the inputElement - for(int i=0; i prefix; //postfix form of the input - stack tempOpertStore; //temporarily stores operators - - tempOpertStore.push(")"); - - for(int i=inputElement.size()-1; !tempOpertStore.empty(); i--){ //conversion - if(!inputElement[i].opert){ - prefix.push_back(inputElement[i].str); - } - else{ - if(inputElement[i].str[0]==')'){ - tempOpertStore.push(inputElement[i].str); - } - else if(inputElement[i].str[0]=='('){ - while(tempOpertStore.top()[0]!=')'){ - prefix.push_back(tempOpertStore.top()); - tempOpertStore.pop(); - } - tempOpertStore.pop(); //pops the ')' - } - else{ - int opertPrecedence = operatorPrecedence(inputElement[i].str); - - while(tempOpertStore.top()[0]!=')'){ - int stackPrecedence = operatorPrecedence(tempOpertStore.top()); - - if(stackPrecedence < opertPrecedence) break; - else{ - prefix.push_back(tempOpertStore.top()); - tempOpertStore.pop(); - } - } - tempOpertStore.push(inputElement[i].str); - } - } - - /*cout << "after " << inputElement[i].str << ": "; //analysing every step - for(int j=0; j=0; i--) //the output - cout << prefix[i] << " " ; - cout << "\n\n"; - - - - return 0; -} - - -double stringToDouble(string str){ //converts a string to a double - double value=0, //holds the value of the string - afterPoint=0; //holds the value after a point - - bool flag = false; //represents if any point is found in the string - int numberOfElementAfterPoint=0; - - for(int i=0; str[i]!=NULL; i++){ - if(str[i]=='.') flag = true; - else{ - if(flag){ - afterPoint = afterPoint*10 + (str[i]-48); - numberOfElementAfterPoint++; - } - else - value = value*10 + (str[i]-48); - } - } - - int divisor=1; //divides the afterPoint element by precise number of 10s - for(int i=0; i -#include -#include -#include - -using namespace std; - - -double stringToDouble(string str); -double exponent(double a, double b); - -struct element{ - string str; //string property - double value; //value of the string - bool opert; //operator-true, operand-false -}; - - -int main(){ - ifstream input; //the input file - - input.open("PostfixEvaluation_Input.txt"); - if(!input.is_open()){ //when file is not found exit - cout << "File name is wrong!\n"; - return 0; - } - - - string s; //stores the input file's element as string - vector inputElement; //holds the behaviour of the input elements - while(input >> s){ //the loop determines the behaviour of the input elements - element elem; - elem.str = s; - - if(s[0]=='+' || s[0]=='-' || s[0]=='*' || s[0]=='/' || s[0]=='^' || s[0]=='(' || s[0]==')'){ //when an operator is found - elem.value = -0.0; - elem.opert = true; - } - else{ - elem.value = stringToDouble(s); //this method converts string to double - elem.opert = false; - } - - inputElement.push_back(elem); - } - - input.close(); //closing the stream - - - /*cout << "string \toperat \tvalue \n"; //output of the inputElement - for(int i=0; i tempOperndStore; //here operands are stored temporarily - - for(int i=0; i -#include -#include -#include - -using namespace std; - - -double stringToDouble(string str); -double exponent(double a, double b); - -struct element{ - string str; //string property - double value; //value of the string - bool opert; //operator-true, operand-false -}; - - -int main(){ - ifstream input; //the input file - - input.open("PrefixEvaluation_Input.txt"); - if(!input.is_open()){ //when file is not found exit - cout << "File name is wrong!\n"; - return 0; - } - - - string s; //stores the input file's element as string - vector inputElement; //holds the behaviour of the input elements - - element el; //pushing a '(' to determine the start - el.opert=true; - el.str="("; - el.value=-0; - inputElement.push_back(el); - - - while(input >> s){ //the loop determines the behaviour of the input elements - element elem; - elem.str = s; - - if(s[0]=='+' || s[0]=='-' || s[0]=='*' || s[0]=='/' || s[0]=='^' || s[0]=='(' || s[0]==')'){ //when an operator is found - elem.value = -0.0; - elem.opert = true; - } - else{ - elem.value = stringToDouble(s); //this method converts string to double - elem.opert = false; - } - - inputElement.push_back(elem); - } - - input.close(); //closing the stream - - - /*cout << "string \toperat \tvalue \n"; //output of the inputElement - for(int i=0; i tempStore; //here operands are stored temporarily - - for(int i=0; i -#include - -using namespace std; - -list creatList(); //creates the list -void traversing(list myList); //prints all the integers in the list -int searching(list myList, int searchingElement); //searches for selected element -list deleting(list myList, int deletingElement, int a); //deleting selected element -list inserting(list myList, int destinationElement, int insertingElement, int a); //inserts certain element in definite place -list destroy(list myList); //destroying the list - - -int main() -{ - list myList; - myList = creatList(); - - while(true) - { - int selection; //user action - cout << "\n##What do you want to do? \npress- 1 for traversing\n"; //user prompt - cout << " 2 for searching\n 3 for deleting\n 4 for inserting\n"; - cout << " 5 for exit\nSelection: "; - cin >> selection; - - - if(selection==1) - traversing(myList); - - else if(selection==2) - { - int searchingElement; //the element to be searched - cout << "Enter the element you want to search for: "; - cin >> searchingElement; - - cout << "\n* " << searchingElement << " is found " << searching(myList, searchingElement) << " times.\n"; - } - - else if(selection==3) - { - int deletingElement; //the element to be deleted - cout << "Enter the element: "; - cin >> deletingElement; - - int a=0; //determines the correct element - cout << "Press 1 for deleting " << deletingElement; - cout << "\n 2 for deleting the element after " << deletingElement << "\nSelection- "; - cin >> a; - - myList = deleting(myList, deletingElement, a); - } - - else if(selection==4) - { - int insertingElement, destinationElement; //the element to be deleted - cout << "Enter the element: "; - cin >> insertingElement; - cout << "Enter the destination element: "; - cin >> destinationElement; - - int a=0; //determines the correct element - cout << "Press 1 for inserting after " << destinationElement; - cout << "\n 2 for inserting before " << destinationElement << "\nSelection- "; - cin >> a; - - myList = inserting(myList, destinationElement, insertingElement, a); - } - - else if(selection==5) break; - - else cout << "#Invalid input!\n"; - } - myList = destroy(myList); -} - - -list creatList() //creates the list -{ - list myList; //declaring the list - int intNumber, //the number of integers - input; //the input that the user gives - - cin >> intNumber; - for(int i=0; i> input; - myList.push_back(input); - } - return myList; -} - -void traversing(list myList) //prints the List -{ - list:: iterator it; //declaring a iterator - - cout << endl; - for(it=myList.begin(); it!=myList.end(); it++) - cout << *it << " "; - cout << endl << endl ; -} - -int searching(list myList, int searchingElement) -{ - int found=0; //number of the searching element - list:: iterator it; //declaring iterator - - for(it=myList.begin(); it!=myList.end(); it++) - if(searchingElement==*it) found++; - - return found; -} - -list deleting(list myList, int deletingElement, int a) -{ - int flag=1; - if(a==1) myList.remove(deletingElement); - else { - list:: iterator it; //declaring iterator - flag=0; - - for(it=myList.begin(); it!=myList.end(); it++){ - if(deletingElement==*it){ - it++; - it=myList.erase(it); - flag=1; - if(it==myList.end()) break; - } - } - } - - if(flag) cout << "\n* Deleted!\n"; - return myList; -} - -list inserting(list myList, int destinationElement, int insertingElement, int a) -{ - int flag=0; - list:: iterator it; //declaring iterator - - for(it=myList.begin(); it!=myList.end(); it++){ - if(destinationElement==*it) { - flag=1; - break; - } - } - if(a==1) it++; - myList.insert(it, insertingElement); - - if(flag) cout << "\n* Inserted!!\n"; - else cout << "Destination not found.\n"; - - return myList; -} - -list destroy(list myList) -{ - myList.clear(); - return myList; -} - - diff --git a/dataStructures/listImplementation/TwoWayLinkedList.cpp b/dataStructures/listImplementation/TwoWayLinkedList.cpp deleted file mode 100644 index 8cf64c3..0000000 --- a/dataStructures/listImplementation/TwoWayLinkedList.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 13.Sep.2013 -**/ - -#include -#include - -using namespace std; - -list creatList(); //creates the list -void traversing(list myList, int choice); //prints all the integers in the list -int searching(list myList, int searchingElement); //searches for selected element -list deleting(list myList, int deletingElement, int selection); //deleting selected element -list insertingAtBeginning(list myList, int insertingElement); //inserting at beginning -list insertingAtEnd(list myList, int insertingElement); //inserting at end -list inserting(list myList, int destinationElement, int insertingElement, int a); //inserts certain element in definite place -list destroy(list myList); //destroying the list - - -int main() -{ - list myList; - myList = creatList(); - - while(true) - { - int selection; //user action - cout << "\n##What do you want to do? \npress- 1 for traversing\n"; //user prompt - cout << " 2 for searching\n 3 for deleting\n 4 for inserting\n"; - cout << " 5 for exit\nSelection: "; - cin >> selection; - - - if(selection==1){ - int choice; - cout << "How do you want to traverse?\npress- 1 for traversing first to last"; - cout << "\n 2 for traversing last to first\nSelection: "; - cin >> choice; - traversing(myList, choice); - } - - else if(selection==2) - { - int searchingElement; //the element to be searched - cout << "Enter the element you want to search for: "; - cin >> searchingElement; - - cout << "\n"; - cout << "* " << searchingElement << " is found " << searching(myList, searchingElement) << " times.\n"; - } - - else if(selection==3) - { - int deletingElement; //the element to be deleted - cout << "Enter the element: "; - cin >> deletingElement; - - int sel=0; //determines the correct element - cout << "Press 1 for deleting " << deletingElement; - cout << "\n 2 for deleting the element after " << deletingElement; - cout << "\n 3 for deleting the element before " << deletingElement << "\nSelection- "; - cin >> sel; - - myList = deleting(myList, deletingElement, sel); - } - - else if(selection==4) - { - int insertingElement, destinationElement, sel; //the element to be deleted - cout << "Enter the element: "; - cin >> insertingElement; - cout << "Where do you want to insert? \nPress 1 for beginning"; - cout << "\n 2 for end\n 3 for chosing destination\nSelection: "; - cin >> sel; - - if(sel==1) myList = insertingAtBeginning(myList, insertingElement); - else if(sel==2) myList = insertingAtEnd(myList, insertingElement); - else{ - cout << "Enter the destination element: "; - cin >> destinationElement; - - int a=0; //determines the correct element - cout << "Press 1 for inserting after " << destinationElement; - cout << "\n 2 for inserting before " << destinationElement << "\nSelection- "; - cin >> a; - - myList = inserting(myList, destinationElement, insertingElement, a); - } - } - - else if(selection==5) break; - - else cout << "#Invalid input!\n"; - } - myList = destroy(myList); -} - - -list creatList() //creates the list -{ - list myList; //declaring the list - int intNumber, //the number of integers - input; //the input that the user gives - - cin >> intNumber; - for(int i=0; i> input; - myList.push_back(input); - } - return myList; -} - -void traversing(list myList, int choice) //prints the List -{ - list:: iterator it; //declaring a iterator - - cout << endl; - if(choice==1) - for(it=myList.begin(); it!=myList.end(); it++) - cout << *it << " "; - else - for(it=myList.end(); it!=myList.begin(); ){ - it--; - cout << *it << " "; - } - cout << endl << endl ; -} - -int searching(list myList, int searchingElement) -{ - int found=0; //number of the searching element - list:: iterator it, //declaring iterator - old=myList.begin(); //this will store old position - - for(it=myList.begin(); it!=myList.end(); it++){ - if(searchingElement==*it){ - it++; - if(old!=myList.begin() && it!=myList.end()){ - cout << "*between " << *old << " and " << *it << endl; - } - else if(old==myList.begin()) cout << "*at beginning\n"; - else cout << "*at end\n"; - it--; - found++; - } - old=it; - } - return found; -} - -list deleting(list myList, int deletingElement, int choice) -{ - int flag=1; - if(choice==1) myList.remove(deletingElement); - else if(choice==2) { - list:: iterator it; //declaring iterator - flag=0; - - for(it=myList.begin(); it!=myList.end(); it++){ - if(deletingElement==*it){ - it++; - it=myList.erase(it); - flag=1; - if(it==myList.end()) break; - } - } - } - else { - list:: iterator it; //declaring iterator - flag=0; - - for(it=myList.begin(); it!=myList.end(); it++){ - if(deletingElement==*it){ - it--; - it=myList.erase(it); - flag=1; - if(it==myList.end()) break; - } - } - } - - if(flag) cout << "\n* Deleted!\n"; - return myList; -} - -list insertingAtBeginning(list myList, int insertingElement) -{ - myList.insert(myList.begin(), insertingElement); - cout << "\n* Inserted!!\n"; - return myList; -} - -list insertingAtEnd(list myList, int insertingElement) -{ - myList.insert(myList.end(), insertingElement); - cout << "\n* Inserted!!\n"; - return myList; -} - -list inserting(list myList, int destinationElement, int insertingElement, int a) -{ - int flag=0; - list:: iterator it; //declaring iterator - - for(it=myList.begin(); it!=myList.end(); it++){ - if(destinationElement==*it) { - flag=1; - break; - } - } - if(a==1) it++; - myList.insert(it, insertingElement); - - if(flag) cout << "\n* Inserted!!\n"; - else cout << "Destination not found.\n"; - - return myList; -} - -list destroy(list myList) -{ - myList.clear(); - return myList; -} - - diff --git a/dataStructures/listImplementation/implementationUsingNode/ListImplementation_Input.txt b/dataStructures/listImplementation/implementationUsingNode/ListImplementation_Input.txt deleted file mode 100644 index 66f95d2..0000000 --- a/dataStructures/listImplementation/implementationUsingNode/ListImplementation_Input.txt +++ /dev/null @@ -1,25 +0,0 @@ -10 - -12 - -45 - -98 - -65 - -31 - -54 - -85 - -25 - -31 - -91 - -25 - -35 diff --git a/dataStructures/listImplementation/implementationUsingNode/OneWayLinkedList.cpp b/dataStructures/listImplementation/implementationUsingNode/OneWayLinkedList.cpp deleted file mode 100644 index 7dce542..0000000 --- a/dataStructures/listImplementation/implementationUsingNode/OneWayLinkedList.cpp +++ /dev/null @@ -1,273 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 17.Sep.2013 -**/ - -#include - -using namespace std; - -struct node -{ - int information; - node *next; -}; - -void traverse(node *nodePointer); -void destroyTheList(node *nodePointer); -void searchAndPrintTheNextElement(int searchingElement, node *nodePointer); -void insertAfterTheElement(int searchingElement, int insertionElement, node *nodePointer); -node* insertBeforeTheElement(int searchingElement, int insertionElement, node *nodePointer); -node* insertAtBeginning(int insertionElement, node *nodePointer); -node* deleteTheElement(int searchingElement, node *nodePointer); -void deleteTheNextElement(int searchingElement, node *nodePointer); - -int main (void) -{ - node *head, *old; //declaring node type pointers - - int count=0; - - int numberOfElements, element; // the variable "numberOfElements" to get the number of the total elements of the list and "element" to insert the element to the list. - cin >> numberOfElements; - - - //creating a one way linked list. - for(int i=0; i> element; - - node *new_node; - new_node = new node[1]; - - new_node[0].information = element; - new_node[0].next = NULL; - - if(count==1)head = &new_node[0]; - else old->next = &new_node[0]; - - old = &new_node[0]; - } - - // calling the functions. - traverse(head); - - int searchingElement; - cin >> searchingElement; - searchAndPrintTheNextElement(searchingElement, head); - - int insertionElement; - cin >> insertionElement; - insertAfterTheElement(searchingElement, insertionElement, head); - - head = insertBeforeTheElement(searchingElement, insertionElement, head); - - head = insertAtBeginning(insertionElement, head); - - head = deleteTheElement(searchingElement, head); - - deleteTheNextElement(searchingElement, head); - - traverse(head); - - destroyTheList(head); - - return 0; -} - - -// traversing the list, all the elements are being printed -void traverse(node *nodePointer) -{ - node *current; - current = nodePointer; - - while(1) - { - cout << current->information << endl; - if(current->next==NULL) break; - current = current->next; - } -} - -//destroy function to destroy the whole list to avoid the memory lickage problem -void destroyTheList(node *nodePointer) -{ - node *current; - - while(nodePointer!=NULL) - { - current=nodePointer; - nodePointer=nodePointer->next; - delete [] current; - } -} - - -// this funtion is to search a specific element and to print the next one -void searchAndPrintTheNextElement(int searchingElement, node *nodePointer) -{ - node *current; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL) cout << "The element " << searchingElement << " not found in the list." << endl; - else cout << "The next element of " << searchingElement << " is " <next->information << "." << endl; -} - -//this funtion is to search a specific element and to insert another one after that -void insertAfterTheElement(int searchingElement, int insertionElement, node *nodePointer) -{ - node *current; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current->next==NULL && current->information==searchingElement) - { - node *new_node; - new_node = new node[1]; - - current->next = &new_node[0]; - new_node[0].information = insertionElement; - new_node[0].next = NULL; - } - - else - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current->next; - current->next = &new_node[0]; - } -} - -//this funtion is to search a specific element and to insert another one before that -node* insertBeforeTheElement(int searchingElement, int insertionElement, node *nodePointer) -{ - node *current, *old; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - old=current; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current==nodePointer) - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current; - nodePointer = &new_node[0]; - } - - else - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = old->next; - old->next = &new_node[0]; - } - - return nodePointer; -} - -//this funtion is to insert an element at the begginig of the list -node* insertAtBeginning(int insertionElement, node *nodePointer) -{ - node *current, *new_node; - current = nodePointer; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current; - nodePointer = &new_node[0]; - - return nodePointer; -} - -//this funtion is to delete a specific element -node* deleteTheElement(int searchingElement, node *nodePointer) -{ - node *current, *old; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - old=current; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current->next==NULL && current->information==searchingElement) - { - old->next = NULL; - delete [] current; - } - - else if(current==nodePointer) - { - nodePointer = current->next; - delete [] current; - } - - else - { - old->next = current->next; - delete [] current; - } - - return nodePointer; -} - -//this funtion is to delete the next element of a specific element -void deleteTheNextElement(int searchingElement, node *nodePointer) -{ - node *current, *old; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL) cout << "Nothing to delete." << endl; - - else - { - old = current; - current = current->next; - old->next = current->next; - delete [] current; - } -} diff --git a/dataStructures/listImplementation/implementationUsingNode/TwoWayLinkedList.cpp b/dataStructures/listImplementation/implementationUsingNode/TwoWayLinkedList.cpp deleted file mode 100644 index ba0ab68..0000000 --- a/dataStructures/listImplementation/implementationUsingNode/TwoWayLinkedList.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 17.Sep.2013 -**/ - -#include - -using namespace std; - -struct node -{ - int information; - node *next, *prev; -}; - -void destroyTheList(node *nodePointer); -void traverse_frontToEnd(node *nodePointer); -void traverse_endToFront(node *nodePointer); -void searchAndPrint(int searchingElement, node *nodePointer); -node* insertAfterTheElement(int searchingElement, int insertionElement, node *nodePointer); -node* insertBeforeTheElement(int searchingElement, int insertionElement, node *nodePointer); -node* insertAtBeginning(int insertionElement, node *nodePointer); -node* deleteTheElement(int searchingElement, node *nodePointer1, node *nodePointer2); -node* deleteTheNextElement(int searchingElement, node *nodePointer1, node *nodePointer2); -node* deleteThePreviousElement(int searchingElement, node *nodePointer1, node *nodePointer2); - -int main(void) -{ - node *head, *tail, *old;//declaring node type pointers - - int count=0; - - int numberOfElements, element;// the variable "numberOfElements" to get the number of the total elements of the list and "element" to insert the element to the list. - cin >> numberOfElements; - - //creating a two way linked list. - for(int i=0; i> element; - - node *new_node; - new_node = new node[1]; - - new_node[0].information = element; - new_node[0].next = NULL; - new_node[0].prev = NULL; - - if(count==1)head = &new_node[0]; - else - { - old->next = &new_node[0]; - new_node[0].prev=old; - } - - old=&new_node[0]; - - } - - tail=old; - - // calling the functions. - traverse_frontToEnd(head); - - traverse_endToFront(tail); - - int searchingElement; - cin >> searchingElement; - searchAndPrint(searchingElement, tail); - - int insertionElement; - cin >> insertionElement; - tail=insertAfterTheElement(searchingElement, insertionElement, head); - - head = insertBeforeTheElement(searchingElement, insertionElement, head); - - head = insertAtBeginning(insertionElement, head); - - head = deleteTheElement(searchingElement, head, tail); - - tail = deleteTheNextElement(searchingElement, head, tail); - - head = deleteThePreviousElement(searchingElement, head, tail); - - traverse_frontToEnd(head); - - destroyTheList(head); -} - -//destroy function to destroy the whole list to avoid the memory lickage problem -void destroyTheList(node *nodePointer) -{ - node *current; - - while(nodePointer!=NULL) - { - current=nodePointer; - nodePointer=nodePointer->next; - delete [] current; - } -} - -// traversing the list from front to end, all the elements are being printed -void traverse_frontToEnd(node *nodePointer) -{ - node *current; - current = nodePointer; - - while(1) - { - cout << current->information << endl; - if(current->next==NULL) break; - current = current->next; - } -} - -// traversing the list from end to front, all the elements are being printed -void traverse_endToFront(node *nodePointer) -{ - node *current; - current = nodePointer; - - while(1) - { - cout << current->information << endl; - if(current->prev==NULL) break; - current = current->prev; - } -} - -// this funtion is to search a specific element and to print the next and the previous elements -void searchAndPrint(int searchingElement, node *nodePointer) -{ - node *current; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->prev==NULL) break; - current=current->prev; - } - - if(current->prev==NULL && current->information!=searchingElement) - { - cout << "The element " << searchingElement << " not found in the list." << endl; - } - - else if(current->prev==NULL && current->information==searchingElement) - { - cout << "The next element: not found" << endl; - cout << "The previous element: " << current->prev->information << endl; - } - - else if(current->next==NULL && current->information==searchingElement) - { - cout << "The next element: " << current->next->information << endl; - cout << "The previous element: not found" << endl; - } - - else - { - cout << "The next element: " << current->next->information << endl; - cout << "The previous element: " << current->prev->information << endl; - } - -} - -//this funtion is to search a specific element and to insert another one after that -node* insertAfterTheElement(int searchingElement, int insertionElement, node *nodePointer) -{ - node *current; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current->next==NULL && current->information==searchingElement) - { - node *new_node; - new_node = new node[1]; - - current->next = &new_node[0]; - - new_node[0].information = searchingElement; - new_node[0].next = NULL; - new_node[0].prev = current; - - nodePointer = &new_node[0]; - } - - else - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current->next; - new_node[0].prev = current; - - current->next = &new_node[0]; - } - - return nodePointer; -} - -//this funtion is to search a specific element and to insert another one before that -node* insertBeforeTheElement(int searchingElement, int insertionElement, node *nodePointer) -{ - node *current; - current=nodePointer; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current==nodePointer) - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current; - new_node[0].prev = NULL; - - current->prev = &new_node[0]; - - nodePointer = &new_node[0]; - } - - else - { - node *new_node; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current; - new_node[0].prev = current->prev; - - current->prev->next=&new_node[0]; - current->prev = &new_node[0]; - - } - - return nodePointer; -} - -//this funtion is to delete a specific element -node* insertAtBeginning(int insertionElement, node *nodePointer) -{ - node *current, *new_node; - current = nodePointer; - new_node = new node[1]; - - new_node[0].information = insertionElement; - new_node[0].next = current; - new_node[0].prev = NULL; - - nodePointer = &new_node[0]; - - return nodePointer; -} - -//this funtion is to delete a specific element -node* deleteTheElement(int searchingElement, node *nodePointer1, node *nodePointer2) -{ - node *current, *old; - current=nodePointer1; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - old=current; - current=current->next; - } - - if(current->next==NULL && current->information!=searchingElement) cout << "Element not found in the list." << endl; - - else if(current->next==NULL && current->information==searchingElement) - { - old->next = NULL; - delete [] current; - } - - else if(current==nodePointer1) - { - nodePointer1 = current->next; - current->next = NULL; - delete [] current; - } - - else if(nodePointer1==nodePointer2) - { - delete [] current; - cout << "The list is empty now." << endl; - } - - else - { - old->next = current->next; - current->next->prev = old; - delete [] current; - } - - return nodePointer1; -} - -//this funtion is to delete the next element of a specific element -node* deleteTheNextElement(int searchingElement, node *nodePointer1, node *nodePointer2) -{ - node *current, *old; - current=nodePointer1; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->next==NULL) cout << "Nothing to delete." << endl; - - else if(current->next==nodePointer2) - { - old = current; - current = current->next; - old->next = current->next; - delete [] current; - nodePointer2 = old; - } - - else - { - old = current; - current = current->next; - old->next = current->next; - delete [] current; - } - - return nodePointer2; -} - -//this funtion is to delete the previous element of a specific element -node* deleteThePreviousElement(int searchingElement, node *nodePointer1, node *nodePointer2) -{ - - node *current, *old; - current=nodePointer1; - - while(1) - { - if(current->information==searchingElement) break; - if(current->next==NULL) break; - current=current->next; - } - - if(current->prev==NULL && current->information==searchingElement && current->information!=searchingElement) cout << "Nothing to delete." << endl; - - if(current->prev==nodePointer1) - { - old = current; - current = current->prev; - delete [] current; - nodePointer1 = old; - old->prev = NULL; - } - - else - { - - current = current->prev; - current->prev->next = current->next; - current->next->prev = current->prev; - delete [] current; - } - return nodePointer1; -} diff --git a/dataStructures/stack/StackImplementation.asm b/dataStructures/stack/StackImplementation.asm deleted file mode 100644 index cfa4eb3..0000000 --- a/dataStructures/stack/StackImplementation.asm +++ /dev/null @@ -1,129 +0,0 @@ -##Writer: Minhas Kamal -##Date: 02-MAY-2014 -##Function: This program is a simple demonstration of stack. - -#####**data**##### -.data - -prompt: .asciiz "\n# What operation do you want to perform?\nPress-\t1.for push \n\t2.for pop \n\t3.for print all \n\t4.for exit \nSelection: " -prompt2: .asciiz "Enter the value: " -conf_pop: .asciiz "\nOperation pop is successful.\n" -conf_push: .asciiz "Operation push is successful.\n" -exit_msg: .asciiz "\n\n\nProgram exits...." -comma_space: .asciiz ", " - -num: .double 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 - .double 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 -capacity: .word 40 -init: .double 0.0 - -#####**text**##### -.text - -main: - lw $t1, capacity #load capacity - l.d $f4, init #load the initial value - li $t2, 0 #initial index is 0 - -loop: - la $a0, prompt #prompt - li $v0, 4 - syscall - - li $v0, 5 #take choice from user - syscall - - la $t0, num #load array - - beq $v0, 1, push - beq $v0, 2, pop - beq $v0, 3, print_all - j exit - - -#------------------------------------------------------------------------------------------------------------------- -#pushes one number on top -push: - li $t3, 0 - - beq $t2, $t1, loop #return when capacity is full - -push_loop: #find the address - add $t0, $t0, 8 - add $t3, $t3, 1 - ble $t3, $t2, push_loop - sub $t0, $t0, 8 #subtract once - - la $a0, prompt2 #prompt for input - li $v0, 4 - syscall - - li $v0, 7 #take input - syscall - - s.d $f0, ($t0) #store the value - - add $t2, $t2, 1 #increase index - - la $a0, conf_push #confirmation - li $v0, 4 - syscall - - j loop #return - - -#------------------------------------------------------------------------------------------------------------------- -#pops up top number -pop: - li $t3, 0 - - beq $t2, $t3, loop #return when nothing to pop - -pop_loop: #find the number - add $t0, $t0, 8 - add $t3, $t3, 1 - blt $t3, $t2, pop_loop - sub $t0, $t0, 8 #subtract once - - - l.d $f12, ($t0) #print the number - li $v0, 3 - syscall - - s.d $f4, ($t0) #initialize - sub $t2, $t2, 1 #reduce index - - la $a0, conf_pop #confirmation - li $v0, 4 - syscall - - j loop #return - -#------------------------------------------------------------------------------------------------------------------- -#prints all the values -print_all: - li $t3, 0 -print_loop: - l.d $f12, ($t0) #print the number - li $v0, 3 - syscall - - la $a0, comma_space #seperate ", " - li $v0, 4 - syscall - - add $t0, $t0, 8 - add $t3, $t3, 1 #increase the loop counter - blt $t3, $t1, print_loop - j loop - - -#------------------------------------------------------------------------------------------------------------------- -#exit from the program -exit: - la $a0, exit_msg #exit message - li $v0, 4 - syscall - - li $v0, 10 - syscall diff --git a/dataStructures/stack/StackImplementation.c b/dataStructures/stack/StackImplementation.c deleted file mode 100644 index 5b66705..0000000 --- a/dataStructures/stack/StackImplementation.c +++ /dev/null @@ -1,69 +0,0 @@ -/** -*Name: Minhas Kamal -*Program Name: StackImplementation -*Date: 04.May.2013 -**/ - -#include - -void stack_size(void); //working functions -void stack_pop(void); -void stack_push(void); - - -char c[5]="*****"; //array - -int main() -{ - for( ; ; ) - { - int dis; //decision input - printf("Enter your selection: \npress\n\t1.stack size\n\t2.stack pop\n\t3.stack push\n\t4.quit\n"); //selection - scanf("%d", &dis); - fflush(stdin); - - if(dis==1) stack_size(); //working according to selection & calling function - else if(dis==2) stack_pop(); - else if(dis==3) stack_push(); - else break; //quit - } - return 0; -} - -void stack_size(void) //shows size -{ - int i; - for(i=4; i>=0; i--) if(c[i]!='*') break; - printf("\nThe size is: %d\n\n\n", i+1); -} - -void stack_pop(void) //printing char -{ - int i; - for(i=4; i>=0; i--) if(c[i]!='*') break; - if(i>=0) - { - printf("\nIt is: %c\n\n\n", c[i]); - c[i]='*'; - } - else printf("\nStack is empty!\n\n\n"); -} - -void stack_push(void) //assigns char -{ - int i; - if(c[4]!='*') - { - printf("\nStack is Full.\n\n\n"); - return ; - } - for(i=4; i>=0; i--) if(c[i]!='*') break; - - fflush(stdin); - char ch; - printf("Enter your input: "); - scanf("%c", &ch); - - c[i+1]=ch; -} - diff --git a/dataStructures/string/String.c b/dataStructures/string/String.c deleted file mode 100644 index 52d80a8..0000000 --- a/dataStructures/string/String.c +++ /dev/null @@ -1,134 +0,0 @@ -/** -* Name: Minhas Kamal (BSSE0509, IIT, DU) -* Date: 26-Mar-2013 -**/ - -#include - -void strlen(int s1); -void strcat(int s1, int s2); -void strcmp(int s1, int s2); - -char s[20][201]; - -int main() -{ - - int x=20; - //scanf("%d", &x); - //printf("Enter the number of strings: "); - - //char s[x][201]; - - int y; - for(y=1; y<=x; y++) - { - printf("Enter string No-%d (not more than 200 chars): ", y); - gets(s[y]); - } - - for( ; ; ) - { - int c; - printf("Enter your choice:\npress\t1 to know the length of string\n\t\t"); - printf("2 to add two strings\n\t\t3 to compare two strings\n\t\t"); - printf("4 to quit.\n\t\t"); - scanf("%d", &c); - - if(c==1) - { - int s1; - printf("Enter string number: "); - scanf("%d", &s1); - strlen(s1); - } - else if(c==2) - { - int s1; - printf("Enter first string number: "); - scanf("%d", &s1); - int s2; - printf("Enter second string number: "); - scanf("%d", &s2); - strcat(s1, s2); - } - else if(c==3) - { - int s1; - printf("Enter first string number: "); - scanf("%d", &s1); - int s2; - printf("Enter second string number: "); - scanf("%d", &s2); - strcmp(s1, s2); - } - else if(c==4) break; - else if(c<1 || c>4) {printf("Wrong input!"); continue ;} - - - } - - return 0; -} - - -void strlen(int s1) -{ - int c1; - for(c1=0; s[s1][c1]!='0'; c1++); - - printf("Number of chars: %d", c1); - - return ; -} - - -void strcat(int s1, int s2) -{ - int c1=0; - char ns[402]; - - int y=0; - for( ; s[s1][c1]!='0'; ) - { - ns[y] = s[s1][c1]; - c1++; - y++; - } - - int z=y, x=0; - for( ; s[s2][x]; ) - { - ns[z] = s[s2][x]; - x++; - z++; - } - ns[z]=0; - - int v=0; - for( ; ns[v]; v++)printf("%c", ns[v]); - - return ; -} - - -void strcmp(int s1, int s2) -{ - int f=1, c1=0, c2=0; - for( ; s[s1][c1]!=0 && s[s2][c2]!=0; ) - { - if(s[s1][c1] != s[s2][c2]) f=0; - - c1++; - c2++; - } - if(s[s1][c1]==0 && s[s2][c2]!=0) f=-1; - else if(s[s2][c2]==0 && s[s1][c1]!=0) f=2; - - if(f==1) printf("String matched."); - else if(f==2) printf("The first one is bigger."); - else if(f==-1) printf("The second one is bigger."); - else if(f==0) printf("Size is same but doesn't match."); - - return ; -} diff --git a/dataStructures/string/StringLongestCommonSubSecuence.cpp b/dataStructures/string/StringLongestCommonSubSecuence.cpp deleted file mode 100644 index 4c4bda2..0000000 --- a/dataStructures/string/StringLongestCommonSubSecuence.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/** -* Name: Minhas Kamal -* Date: 23-Mar-2014 -**/ - -#include -#include - -using namespace std; - - -void LCSFinder(char *firstString, char *secondString); -int stringLength(char *string); -void printLcs(char **direction, char *firstString, int i, int j); - - -int main(){ - int length = 100; - char firstString[length], - secondString[length]; - - cout << "Enter two strings: "; - cin >> firstString >> secondString; - - cout << "Longest common sub-sequence is: "; - LCSFinder(firstString, secondString); - cout << "\n"; - - - return 0; -} - - -void LCSFinder(char *firstString, char *secondString){ - int firstStringLength = stringLength(firstString), - secondStringLength = stringLength(secondString); - //cout << firstStringLength << " " << secondStringLength; - - int index[firstStringLength+1][secondStringLength+1]; - - char **direction; - direction = new char* [firstStringLength]; - for(int i=0; i=index[i][j-1]){ - index[i][j]=index[i-1][j]; - direction[i-1][j-1]='|'; //up - } - else{ - index[i][j]=index[i][j-1]; - direction[i-1][j-1]='-'; //side - } - } - } - - cout << "\nMatrix: \n"; - for(int i=0; i -#include -#include -#include - -using namespace std; - -#define X 30 - -int main(){ - int array[X+1]; - array[0]=0; - for(int i=1; i=array[j]){ - if(position[j]>position[i]){ - position[i]=position[j]; - prevIndex[i]=j; - } - } - } - position[i]++; - } - - ///traverse ///test - /*for(int i=0; ilength){ - length=position[i]; - index=i; - } - } - - ///sub sequence - stack subSequence; - while(prevIndex[index]!=0){ - subSequence.push(array[index]); - index = prevIndex[index]; - } - subSequence.push(array[index]); - - while(!subSequence.empty()){ - cout << subSequence.top() << endl; - subSequence.pop(); - } - - return 0; -} diff --git a/dataStructures/tree/BinaryHeap.cpp b/dataStructures/tree/BinaryHeap.cpp deleted file mode 100644 index a2ae183..0000000 --- a/dataStructures/tree/BinaryHeap.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/** -* Programmer: Minhas Kamal (BSSE0509,IIT,DU) -* Date: 18-Apr-2014 -**/ - -#include -#include -#include - -using namespace std; - -struct node{ - int value; - node *next[2]; - node *previous; -}; - -int main(){ - ///any integerarray - int length=18; - int array[]={12,23,34,4,5,6,676,78,8,34,32,3,5,657,6,54,4,4}; - - ///main node - node elements[100]; - for(int i=0; i<100; i++){ - elements[i].value=-4200; - - elements[i].next[0]=NULL; - elements[i].next[1]=NULL; - elements[i].previous=NULL; - } - - elements[0].value=array[0]; - elements[0].next[0]=&elements[1]; - elements[0].next[1]=&elements[2]; - elements[0].previous=NULL; - - ///constructs the binary heap - for(int i=1; ivalue){ - int temp=elements[position].value; - elements[position].value=elements[position].previous->value; - elements[position].previous->value=temp; - - - position=(int) (position-1)/2; - } - else{ - break; - } - } - } - - - ///traverse - cout << "After making binary heap-> "; - for(int i=0; i> selection; - - if(selection==1){ //find minimum - cout << "Minimum element is: " << elements[0].value; - } - else if(selection==2){ //delete minimum - int value=elements[0].value; - elements[0].value=elements[currentPosition-1].value; - elements[currentPosition-1].value=value; - - currentPosition--; - - int position=0; - while(2*position < currentPosition){ - if(elements[position].value > elements[position].next[1]->value && - elements[position].next[1]->value <= elements[position].next[0]->value){ - int temp=elements[position].value; - elements[position].value=elements[position].next[1]->value; - elements[position].next[1]->value=temp; - - position=2*position+2; - }else if(elements[position].value > elements[position].next[0]->value){ - int temp=elements[position].value; - elements[position].value=elements[position].next[0]->value; - elements[position].next[0]->value=temp; - - position=2*position+1; - }else{ - break; - } - } - - cout << "Minimum is Deleted!"; - } - else if(selection==3){ //insert new - int value; - cout << "\nEnter the value: "; - cin >> value; - - elements[currentPosition].value=value; - - elements[currentPosition].next[0]=&elements[2*currentPosition+1]; - elements[currentPosition].next[1]=&elements[2*currentPosition+2]; - elements[currentPosition].previous=&elements[(int)((currentPosition-1)/2)]; - - - int position=currentPosition; - while(elements[position].previous!=NULL){ - if(elements[position].value < elements[position].previous->value){ - int temp=elements[position].value; - elements[position].value=elements[position].previous->value; - elements[position].previous->value=temp; - - - position=(int) (position-1)/2; - }else{ - break; - } - } - - - currentPosition++; - cout << "Inserted!"; - } - else if(selection==4){ //delete - int value; - cout << "\nEnter the value of the element: "; - cin >> value; - - int position=-1; - for(int i=0; i elements[position].next[1]->value && - elements[position].next[1]->value <= elements[position].next[0]->value){ - int temp=elements[position].value; - elements[position].value=elements[position].next[1]->value; - elements[position].next[1]->value=temp; - - position=2*position+2; - }else if(elements[position].value > elements[position].next[0]->value){ - int temp=elements[position].value; - elements[position].value=elements[position].next[0]->value; - elements[position].next[0]->value=temp; - - position=2*position+1; - }else{ - break; - } - } - cout << "Deleted!"; - } - } - else if(selection==5){ //edit - int value; - cout << "\nEnter the value of the element: "; - cin >> value; - - int position=-1; - for(int i=0; ivalue){ - int temp=elements[position].value; - elements[position].value=elements[position].previous->value; - elements[position].previous->value=temp; - - position=(int) (position-1)/2; - } - else{ - break; - } - } - - cout << "Edited!"; - } - } - else if(selection==6){ //traverse - for(int i=0; i -#include -#include - -using namespace std; - -#define X 3 - -struct node{ - int value; - int depth; - node *previous; - node *next[X]; -} nullNode; - - - -int main(){ - ///input array - int arrayLength=1; - for(int i=0; idepth==binomialTree[newNode].depth) - similarityFound=true; - } - - if(similarityFound){ - if(binomialTree[j].value < binomialTree[newNode].value){ - binomialTree[j].next[binomialTree[j].depth]=&binomialTree[newNode]; - binomialTree[newNode].previous=&binomialTree[j]; - newNode=j; - binomialTree[j].depth++; - } - else{ - binomialTree[newNode].next[binomialTree[newNode].depth]=&binomialTree[j]; - binomialTree[j].previous=&binomialTree[newNode]; - newNode=newNode; - binomialTree[newNode].depth++; - } - - nullNode.depth--; - nullNode.next[nullNode.depth]=&binomialTree[newNode]; - - }else{ - break; - } - - } - } - - ///traversing - for(int i=0; i -#include - -using namespace std; - -int main(int argc, char *argv[]){ - //**taking the file name - string fileName=""; - if(argc>1){ - fileName=argv[1]; - }else{ - cout << "Enter the file name: "; - cin >> fileName; - //fileName="ASInput.txt";//test - } - - - //**opening the file - ifstream input; - input.open(fileName.c_str()); - if(!input.is_open()){ //when the file name is wrong - printf("Sorry the file is not found!"); - input.close(); - return 1; - } - - - //**reading file - int n; - input >> n; - int time[n][3]; ///colour, start position, stop position - - int i=0; - for(; i> time[i][1] >> time[i][2]; - } - input.close(); - - - /*////test - int t; - cout << endl; - for(t=0; t touples = new LinkedList(); - - Scanner scanner = new Scanner(System.in); - System.out.println("Enter your touples(0 for exit): "); - - String[] tempStrings; - tempStrings = scanner.nextLine().split(" "); - while(!tempStrings[0].equals("0")){ - touples.add(new Touple(tempStrings)); - tempStrings = scanner.nextLine().split(" "); - } - - return touples.toArray(new Touple[0]); - } - - private Touple[] takeInput2(){ - LinkedList touples = new LinkedList(); - - int[] i = new int[3]; - - i[0]=2; i[1]=3; i[2]=9; touples.add(new Touple(i.clone())); - i[0]=4; i[1]=9; i[2]=4; touples.add(new Touple(i.clone())); - i[0]=3; i[1]=5; i[2]=0; touples.add(new Touple(i.clone())); - i[0]=6; i[1]=8; i[2]=2; touples.add(new Touple(i.clone())); - i[0]=8; i[1]=1; i[2]=1; touples.add(new Touple(i.clone())); - i[0]=1; i[1]=4; i[2]=5; touples.add(new Touple(i.clone())); - i[0]=6; i[1]=2; i[2]=8; touples.add(new Touple(i.clone())); - i[0]=7; i[1]=3; i[2]=2; touples.add(new Touple(i.clone())); - - return touples.toArray(new Touple[0]); - } - - private void traverse(Touple[] touples) { - String str = "[" + touples[0].dupm(); - for(int i=1; i touples[j].values[elementNumber]){ - Touple temp = touples[i]; - touples[i] = touples[j]; - touples[j] = temp; - } - } - } - } - - private void constructBalanceTree(Touple[] touples, int startRange, int finishRange, int step) { - - partialSort(touples, startRange, finishRange, step%touples[0].values.length); - - int divider = (startRange+finishRange)/2; - System.out.println(touples[divider].values[step%touples[0].values.length]); - traverse(touples); - - if(finishRange-startRange>2){ - step++; - constructBalanceTree(touples, startRange, divider, step); - constructBalanceTree(touples, divider, finishRange, step); - } - - return ; - } - - public static void main(String[] args) { - BalanceTree balanceTree = new BalanceTree(); - balanceTree.CreateBalanceTree(); - } -} diff --git a/dataStructures/tree/balanceTree/Touple.java b/dataStructures/tree/balanceTree/Touple.java deleted file mode 100644 index 9daca3a..0000000 --- a/dataStructures/tree/balanceTree/Touple.java +++ /dev/null @@ -1,48 +0,0 @@ -/** -* Developer: Minhas Kamal(BSSE0509, IIT, DU) -* Date: 09-Feb-2015 -**/ - -package balanceTree; - -public class Touple { - public int[] values; - - public Touple() { - values = new int[3]; - for(int i=0; i<3; i++){ - values[i] = 0; - } - } - - public Touple(int[] values) { - this.values = values; - } - - public Touple(String[] values) { - this.values = new int[values.length]; - - for(int i=0; i> tree = new LinkedList<>(); - - public static void main(String[] args) { - //data = convertStringToInt(takeInput()); - - data = takeInput2(); - traverse(data); - System.out.println("\n##################\n"); - - int dimention = 0; - int level = 0; - constructTree(data, 0, data.length, dimention, level); - - System.out.println("\n##################\n"); - traverse(data); - - printTree(tree); - } - - private static String[][] takeInput(){ - LinkedList inputData = new LinkedList<>(); - - @SuppressWarnings("resource") - Scanner scanner = new Scanner(System.in); - System.out.println("Enter your input (0 for exit): "); - String[] inputStr = scanner.nextLine().split(" "); - while(!inputStr[0].equals("0")){ - inputData.add(inputStr); - inputStr = scanner.nextLine().split(" "); - } - - String[][] stringData = new String[inputData.size()][]; - stringData = inputData.toArray(stringData); - - return stringData; - } - - private static int[][] convertStringToInt(String[][] strdata){ - int firstDLen = strdata.length; - int secondDLen = strdata[0].length; - - int[][] data = new int[firstDLen][secondDLen]; - for(int i=0; i data[j][dimention]){ - int[] temp = data[i]; - data[i] = data[j]; - data[j] = temp; - } - } - } - - //if there is more than one member - if(to-from > 1){ - traverse(data);//output - if(tree.size() ints = new LinkedList(); - tree.add(ints); - } - tree.get(level).add(data[(from+to)/2][dimention]); - - level++; - dimention++; - if(dimention>=data[0].length){ - dimention=0; - } - - //recursive call - constructTree(data, from, (from+to)/2, dimention, level); - constructTree(data, (from+to)/2, to, dimention, level); - } - - return; - } - - private static void printTree(LinkedList> tree){ - for(LinkedList elem: tree){ - for(int node: elem){ - System.out.println(node + "\t"); - } - System.out.println(); - } - } -} diff --git a/google602017266890774d.html b/google602017266890774d.html new file mode 100644 index 0000000..b3a0f9d --- /dev/null +++ b/google602017266890774d.html @@ -0,0 +1 @@ +google-site-verification: google602017266890774d.html \ No newline at end of file diff --git a/graph/breathFirstSearch/BreadthFirstSearch.cpp b/graph/breathFirstSearch/BreadthFirstSearch.cpp deleted file mode 100644 index 620b043..0000000 --- a/graph/breathFirstSearch/BreadthFirstSearch.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 12.Nov.2013 -**/ - -#include -#include -#include - -using namespace std; - -void printPath(int* colour, int* distance, int* previous, int startVertex, int queryVertex); - -int main()//(int argc, char* argv[]) -{ - ifstream graph; //input file stream - graph.open("BreadthFirstSearch_Input2.txt"); - //graph.open(argv[1]); - - if(!graph.is_open()){ //when file is not found - cout << "File name is wrong!\n"; - return 0; - } - - int vertexNumber, **matrix; - graph >> vertexNumber; - matrix = new int* [vertexNumber]; - for(int i=0; i> matrix[i][j]; - - - - /*for(int i=0; i> startVertex; - startVertex = startVertex-1; - - ///Start of BFS - queue bFSQueue; - bFSQueue.push(startVertex); - - colour[startVertex]=2; //colour is set to grey - distance[startVertex]=0; //distance is zero - previous[startVertex]=-2; //there is no previous - - while(!bFSQueue.empty()){ //finding adjacent vertexes and colouring them - int i=bFSQueue.front(); - bFSQueue.pop(); - colour[i]=3; - - for(int j=0; j> queryVertex; - queryVertex = queryVertex-1; - - cout << "\n\nThe Path is: \n"; - printPath(colour, distance, previous, startVertex, queryVertex); - - - for(int i=0; i -#include -#include - -using namespace std; - -int main()//(int argc, char* argv[]) -{ - ifstream graph; //input file stream - graph.open("DepthFirstSearch_Input.txt"); - //graph.open(argv[1]); - - if(!graph.is_open()){ //when file is not found - cout << "File name is wrong!\n"; - return 0; - } - - int vertexNumber, **matrix; - graph >> vertexNumber; - matrix = new int* [vertexNumber]; - for(int i=0; i> matrix[i][j]; - - - - /*/for(int i=0; i> startVertex; - startVertex = startVertex-1; - - ///start of DFS - stack dFSStack; - dFSStack.push(startVertex); - - colour[startVertex]=2; //colour is set to grey - - cout << "Reachable vertexes are: \n"; - while(!dFSStack.empty()){ - int i=dFSStack.top(); - dFSStack.pop(); - - for(int j=0; j -#include -#include - -using namespace std; - - -int FordFulkerson(int **matrix, int vertexNumber, int s, int t); -bool BFS(int **residualGraph, int vertexNumber, int s, int t, int parent[]); - - -int main(){ - ifstream graph; //input file stream - graph.open("MaxFlow_Input.txt"); - - if(!graph.is_open()){ //when file is not found - cout << "File name is wrong!\n"; - return 0; - } - - int vertexNumber, **matrix; - graph >> vertexNumber; - matrix = new int* [vertexNumber]; - for(int i=0; i> matrix[i][j]; - - graph.close(); //close the file graph - - /*for(int i=0; i residualGraph[parent[v]][v]){ - pathFlow=residualGraph[parent[v]][v]; - } - } - - - for(int v=t; v!=s; v=parent[v]){ - residualGraph[parent[v]][v] = residualGraph[parent[v]][v] - pathFlow; - residualGraph[v][parent[v]] = residualGraph[parent[v]][v] + pathFlow; - } - - maxFlow = maxFlow+pathFlow; - } - - return maxFlow; -} - - -//classic BFS -bool BFS(int **residualGraph, int vertexNumber, int s, int t, int parent[]){ - - bool visited[vertexNumber]; - for(int i=0; i vertexQueue; - - vertexQueue.push(s); - parent[s]=-1; - visited[s]=true; - - while(!vertexQueue.empty()){ - int v=vertexQueue.front(); - vertexQueue.pop(); - - for(int i=0; i0){ - vertexQueue.push(i); - parent[i]=v; - visited[i]=true; - } - } - } - - return visited[t]; -} - diff --git a/graph/maxFlow/MaxFlow_Input.png b/graph/maxFlow/MaxFlow_Input.png deleted file mode 100644 index fa921da..0000000 Binary files a/graph/maxFlow/MaxFlow_Input.png and /dev/null differ diff --git a/graph/maxFlow/MaxFlow_Input.txt b/graph/maxFlow/MaxFlow_Input.txt deleted file mode 100644 index 9ad6b93..0000000 --- a/graph/maxFlow/MaxFlow_Input.txt +++ /dev/null @@ -1,7 +0,0 @@ -6 -0 12 5 0 8 0 -0 0 2 0 0 7 -0 0 0 14 0 0 -0 0 0 0 0 15 -0 0 0 3 0 0 -0 0 0 0 0 0 \ No newline at end of file diff --git a/graph/shortestPathAlgorithm/ShortestPathAlgorithm.cpp b/graph/shortestPathAlgorithm/ShortestPathAlgorithm.cpp deleted file mode 100644 index 2baf291..0000000 --- a/graph/shortestPathAlgorithm/ShortestPathAlgorithm.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 13.Nov.2013 -**/ - -#include -#include -#include - -using namespace std; - -void printPath(int* distance, int* previous, int startVertex, int queryVertex); - -int main(){ - ifstream graph; //input file stream - graph.open("ShortestPathAlgorithm_Input.txt"); - //graph.open(argv[1]); - - if(!graph.is_open()){ //when file is not found - cout << "File name is wrong!\n"; - return 0; - } - - int vertexNumber, **matrix; - graph >> vertexNumber; - matrix = new int* [vertexNumber]; - for(int i=0; i> matrix[i][j]; - - - - /*/for(int i=0; i> startVertex; - startVertex = startVertex-1; - - ///Start of SPA - queue SPAQueue; - SPAQueue.push(startVertex); - - distance[startVertex]=0; //distance is zero - previous[startVertex]=-2; //there is no previous - - while(!SPAQueue.empty()){ //finding adjacent vertexes and colouring them - int i=SPAQueue.front(); - SPAQueue.pop(); - - for(int j=0; jdistance[i]+matrix[i][j])){ - distance[j]=distance[i]+matrix[i][j]; - previous[j] =i; - SPAQueue.push(j); - } - } - - /*/cout << endl; - for(int i=0; i> queryVertex; - queryVertex = queryVertex-1; - - cout << "\n\nThe distance is: " << distance[queryVertex]; - - cout << "\nThe Path is: \n"; - printPath(distance, previous, startVertex, queryVertex); - - - for(int i=0; i -#include -#include - -using namespace std; - -int main()//(int argc, char* argv[]) -{ - ifstream graph; //input file stream - graph.open("TopologicalSort_Input.txt"); - //graph.open(argv[1]); - - if(!graph.is_open()){ //when file is not found - cout << "File name is wrong!\n"; - return 0; - } - - int vertexNumber, **matrix; - graph >> vertexNumber; - matrix = new int* [vertexNumber]; - for(int i=0; i> matrix[i][j]; - - - - /*for(int i=0; i sortedList; - for(int x=0; x dFSStack; - dFSStack.push(startVertex); - sortedList.push(startVertex); - - colour[startVertex]=2; //colour is set to grey - - while(!dFSStack.empty()){ - int i=dFSStack.top(); - dFSStack.pop(); - - for(int j=0; j=0; i--) - cout << "\t\t" << result[i]+1 << endl; - - - for(int i=0; i + + + + + + + + + + + + + + Algorithm Implementations by Minhas Kamal + + + +
+
+

Algorithm Implementations

+

Implementation of Elementary Algorithms

+ View project on GitHub +
+
+ +
+
+
+

The project contains algorithms that were implemented in my Data Structure & Algorithms course. Yes, I got marks for those. 😎

+ +

+Categorical List of Algorithms

+ +

AlgorithmImplementations
+ ├─ arithmeticExpressions
+ │ ├─ InfixEvaluation
+ │ ├─ InfixToPostfix
+ │ ├─ InfixToPrefix
+ │ ├─ PostfixEvaluation
+ │ └─ PrefixEvaluation
+ ├─ dataStructures
+ │ ├─ listImplementation
+ │ │ ├─ implementationUsingNode
+ │ │ │ ├─ OneWayLinkedList
+ │ │ │ └─ TwoWayLinkedList
+ │ │ ├─ OneWayLinkedList
+ │ │ └─ TwoWayLinkedList
+ │ ├─ stack
+ │ │ └─ StackImplementation
+ │ ├─ string
+ │ │ ├─ String
+ │ │ ├─ StringLongestCommonSubSecuence
+ │ │ └─ StringLongestIncreasingSubSecuence
+ │ └─ tree
+ │   ├─ ActivitySelection
+ │   ├─ BalanceTree
+ │   ├─ KdTree
+ │   ├─ BinaryHeap
+ │   └─ BinomialTree
+ ├─ graph
+ │ ├─ BreathFirstSearch
+ │ ├─ DepthFirstSearch
+ │ ├─ MaxFlow
+ │ ├─ ShortestPathAlgorithm
+ │ └─ TopologicalSort
+ ├─ numericalMethods
+ │ ├─ calculus
+ │ │ ├─ DerivetivesOnDifferentPoints
+ │ │ ├─ IntegrationForwardInterpolation
+ │ │ ├─ IntegrationSimpsonRule
+ │ │ └─ IntersectingArea
+ │ └─ equationSolving
+ │   ├─ LinearEquationSolvingProcess
+ │   │ ├─ JacobisMethod
+ │   │ └─ GaussSeidalMethod
+ │   └─ NonLinearEquationSolvingProcess
+ │     ├─ BisectionMethod
+ │     ├─ FalsePosition
+ │     ├─ NewtonRaphson
+ │     ├─ FixedPoint
+ │     └─ Secant
+ ├─ others
+ │ ├─ cigaretteSmokersProblem
+ │ ├─ geneticAlgorithm
+ │ └─ huffmanAlgorithm
+ ├─ search
+ │ ├─ AStarSearch
+ │ ├─ BinarySearch
+ │ └─ KnuthMorrisPrattAlgorithm
+ ├─ sort
+ │ └─ QuickSort
+ └─ thread
+   ├─ priorityBased
+   │ ├─ nonpremitive
+   │ └─ premitive
+   └─ shortestJob
+     ├─ nonpremitive
+     └─ premitive

+ +

+License

+ +

GNU General Public License
This project is licensed under GNU General Public License version-3.

+
+ + +
+
+ + + + diff --git a/javascripts/main.js b/javascripts/main.js new file mode 100644 index 0000000..d8135d3 --- /dev/null +++ b/javascripts/main.js @@ -0,0 +1 @@ +console.log('This would be the main JS file.'); diff --git a/numericalMethods/calculus/DerivetivesOnDifferentPoints.c b/numericalMethods/calculus/DerivetivesOnDifferentPoints.c deleted file mode 100644 index debffe3..0000000 --- a/numericalMethods/calculus/DerivetivesOnDifferentPoints.c +++ /dev/null @@ -1,43 +0,0 @@ -/******************************** -* Developer: Minhas Kamal(BSSE0509) -* Date: Mar-2014 -********************************/ - -#include -#include - - -int main(){ - int n=201; - - double x[n], fx[n], fx2[n]; - - double a=0.0, b=2*M_PI; - double h=(b-a)/n; - - - int i; - x[0]=a; - fx[0]=sin(x[0]); //calculation of function - for(i=1; i -#include - - -#define f(x) sin(x) - - -int main(){ - int n=100; - double a=0.0, b=M_PI; - double h=(b-a)/n; - - double I=0; - int i; - - I = I + 0.5*f(a); - for(i=1; i -#include - - -#define f(x) sin(x) - - -int main(){ - int n=100; - double a=0.0, b=M_PI; - double h=(b-a)/n; - - double I=0; - int i; - - I = I + f(a); - for(i=1; i -#include - - -#define f1(x) ((x)-5) * ((x)-5) -#define f2(x) 0 -#define f(x) (f1(x))-(f2(x)) - -int main(){ - int n=100; - double a=-5, b=5; - double h=(b-a)/n; - - double I=0; - int i; - - I = I + 0.5*f(a); - for(i=1; i - - -void JacobisMethod(int n, double x[n], double b[n], double a[n][n]); -void GaussSeidalMethod(int n, double x[n], double b[n], double a[n][n]); -void print(int n, double x[n]); - - -int main(){ - int n=3; //number of variables - - double x[n]; //variables - - double b[n], //constants - a[n][n]; //arguments - - //assign values - a[0][0]=8; a[0][1]=2; a[0][2]=-2; b[0]=8; - a[1][0]=1; a[1][1]=-8; a[1][2]=3; b[1]=-4; - a[2][0]=2; a[2][1]=1; a[2][2]=9; b[2]=12; - - int i; - - for(i=0; i -0.000001 && (Nx[i]-x[i])/x[i] < 0.000001 )){ - rootFound=0; - break; - } - } - - for(i=0; i -0.000001 && (Nx[i]-x[i])/x[i] < 0.000001 )){ - rootFound=0; - break; - } - } - - for(i=0; i -#include - - -/// Here define different functions to work with -//1st function set -#define f(x) ( ((x)*(x)*(x)) - (x) - 2 ) -#define f2(x) ( (3*(x)*(x)) - 1 ) -#define g(x) ( cbrt( (x) + 2 ) ) -//2nd function set -//#define f(x) ( ((x)*(x)*(x)) - (4*(x)) - 8.95 ) -//#define f2(x) ( (3*(x)*(x)) - 4 ) -//#define g(x) ( cbrt( (4*(x)) + 8.95 ) ) - - -//functions using different methods in solving the same problem -double BisectionMethod(); -double FalsePosition(); -double NewtonRaphson(); -double FixedPoint(); -double Secant(); - - -int main(){ - double root; - - root = BisectionMethod(); - printf("Using Bisection Method the root is: %lf \n\n", root); - - root = FalsePosition(); - printf("Using False Position Method the root is: %lf \n\n", root); - - root = NewtonRaphson(); - printf("Using Newton-Raphson Method the root is: %lf \n\n", root); - - root = FixedPoint(); - printf("Using Fixed Point Method the root is: %lf \n\n", root); - - root = Secant(); - printf("Using Secant Method the root is: %lf \n\n", root); - - return 0; -} - -/** -* takes two initial values and shortens the distance by both side -**/ -double BisectionMethod(){ - double root=0; - - double a=1, b=2; - double c=0; - - int loopCounter=0; - if(f(a)*f(b) < 0){ - while(1){ - loopCounter++; - c=(a+b)/2; - - if(f(c)<0.00001 && f(c)>-0.00001){ - root=c; - break; - } - - if((f(a))*(f(c)) < 0){ - b=c; - }else{ - a=c; - } - - } - } - printf("It took %d loops.\n", loopCounter); - - return root; -} - -/** -* takes two initial values and shortens the distance by single side -**/ -double FalsePosition(){ - double root=0; - - double a=1, b=2; - double c=0; - - int loopCounter=0; - if(f(a)*f(b) < 0){ - while(1){ - loopCounter++; - - c=(a*f(b) - b*f(a)) / (f(b) - f(a)); - - /*/printf("%lf\t %lf \n", c, f(c));/**////test - if(f(c)<0.00001 && f(c)>-0.00001){ - root=c; - break; - } - - if((f(a))*(f(c)) < 0){ - b=c; - }else{ - a=c; - } - } - } - printf("It took %d loops.\n", loopCounter); - - return root; -} - -/** -* uses one initial value and gradually takes that value near to the real one -**/ -double NewtonRaphson(){ - double root=0; - - double x1=1; - double x2=0; - - int loopCounter=0; - while(1){ - loopCounter++; - - x2 = x1 - (f(x1)/f2(x1)); - /*/printf("%lf \t %lf \n", x2, f(x2));/**////test - - if(f(x2)<0.00001 && f(x2)>-0.00001){ - root=x2; - break; - } - - x1=x2; - } - printf("It took %d loops.\n", loopCounter); - - return root; -} - -/** -* uses one initial value and gradually takes that value near to the real one -**/ -double FixedPoint(){ - double root=0; - double x=1; - - int loopCounter=0; - while(1){ - loopCounter++; - - if( (x-g(x)) <0.00001 && (x-g(x)) >-0.00001){ - root = x; - break; - } - - /*/printf("%lf \t %lf \n", g(x), x-(g(x)));/**////test - - x=g(x); - } - printf("It took %d loops.\n", loopCounter); - - return root; -} - -/** -* uses two initial values & both value approaches to the root -**/ -double Secant(){ - double root=0; - - double x0=1; - double x1=2; - double x2=0; - - int loopCounter=0; - while(1){ - loopCounter++; - - /*/printf("%lf \t %lf \t %lf \n", x0, x1, f(x1));/**////test - - if(f(x1)<0.00001 && f(x1)>-0.00001){ - root=x1; - break; - } - - x2 = ((x0*f(x1))-(x1*f(x0))) / (f(x1)-f(x0)); - - x0=x1; - x1=x2; - } - printf("It took %d loops.\n", loopCounter); - - return root; -} - diff --git a/others/cigaretteSmokersProblem/Agent.java b/others/cigaretteSmokersProblem/Agent.java deleted file mode 100644 index c91ec69..0000000 --- a/others/cigaretteSmokersProblem/Agent.java +++ /dev/null @@ -1,49 +0,0 @@ -/** -* Name: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 04-Dec-2014 -**/ - -package cigaretteSmokersProblem; - -import java.util.LinkedList; -import java.util.Queue; -import java.util.Random; - -public class Agent { - private Smoker[] smokers; - - public Agent(Smoker[] smokers) { - this.smokers = smokers; - } - - public Queue start(int time){ - Queue symbols = new LinkedList(); - - int i=0; - while(i symbols = agent.start(800); - - new Graph(symbols).setVisible(true); - } - - - public static void main(String[] args) { - new CigaretteSmokersProblemMain(); - } -} diff --git a/others/cigaretteSmokersProblem/Graph.java b/others/cigaretteSmokersProblem/Graph.java deleted file mode 100644 index 2606181..0000000 --- a/others/cigaretteSmokersProblem/Graph.java +++ /dev/null @@ -1,153 +0,0 @@ -/** -* Name: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 04-Dec-2014 -**/ - -package cigaretteSmokersProblem; - -import java.awt.Color; -import java.util.*; -import javax.swing.*; - -@SuppressWarnings("serial") -public class Graph extends JFrame{ - //** - // Variable Declaration #*******D*******# - //** - private JPanel jPanelMain; - private JPanel[] jPanelGraph; - - //other variables - private final int LENGTH = 640; - - private int parts; - // End of Variable Declaration #_______D_______# - - /***##Constructor##***/ - public Graph(Queue symbols) { - parts = symbols.size(); - - initialComponent(symbols); - } - - - /** - * Method for Initializing all the GUI variables, placing them all to specific space on the frame and adding action - * listener to them. Also specifies criteria of the main frame. - */ - private void initialComponent(Queue symbols) { - //** - // Initialization #*******I*******# - //** - jPanelMain = new JPanel(); - jPanelGraph = new JPanel[parts]; - //other variables - Queue uniqueSymbols = new LinkedList(); - // End of Initialization #_______I_______# - - //** - // Setting Bounds and Attributes of the Elements #*******S*******# - //** - jPanelMain.setBounds(0, 0, LENGTH+40, 250); - jPanelMain.setBackground(new Color(-1)); - jPanelMain.setLayout(null); - - int partLength = LENGTH/parts; - for(int i=0; i symbol = new LinkedList(); - symbol.add('a');symbol.add('a');symbol.add('b');symbol.add('c'); - symbol.add('a');symbol.add('c');symbol.add('c');symbol.add('d'); - symbol.add('a');symbol.add('b');symbol.add('c');symbol.add('e'); - symbol.add('f');symbol.add('f');symbol.add('f');symbol.add('c'); - symbol.add('a');symbol.add('g');symbol.add('g');symbol.add('d'); - symbol.add('h');symbol.add('h');symbol.add('h');symbol.add('e'); - symbol.add('a');symbol.add('a');symbol.add('c');symbol.add('c'); - symbol.add('i');symbol.add('j');symbol.add('k');symbol.add('i'); - symbol.add('j');symbol.add('j');symbol.add('j');symbol.add('k'); - - Graph gui = new Graph(symbol); - gui.setVisible(true); - } - - //** - // Auxiliary Methods #********AM*******# - //** - - private int getPosition(char symbol, Queue uniqueSymbols){ - int position = -1; - - int p = 0; - for(Character uniqueSymbol: uniqueSymbols){ - if(symbol==uniqueSymbol){ - position=p; - break; - } - p++; - } - - return position; - } - - private Color getColor(int i){ - i *= 150; - - int r = i%256; - int g = i%200+i%56; - int b = i%100+i%156; - - Color color = new Color(r, g, b); - return color; - } - // End of Auxiliary Methods #________AM_______# -} diff --git a/others/cigaretteSmokersProblem/Smoker.java b/others/cigaretteSmokersProblem/Smoker.java deleted file mode 100644 index 5f1e0eb..0000000 --- a/others/cigaretteSmokersProblem/Smoker.java +++ /dev/null @@ -1,16 +0,0 @@ -/** -* Name: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 04-Dec-2014 -**/ - -package cigaretteSmokersProblem; - -public class Smoker { - public char ingredient; - public int smokingTime; - - public Smoker(char ingredient, int smokingTime) { - this.ingredient = ingredient; - this.smokingTime = smokingTime; - } -} diff --git a/others/geneticAlgorithm/Board.java b/others/geneticAlgorithm/Board.java deleted file mode 100644 index 8a899bd..0000000 --- a/others/geneticAlgorithm/Board.java +++ /dev/null @@ -1,216 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 01.Sep.2015 -* Comment: This is a chess board made only for queens. -**/ - -package nQueenProblem; - -import java.util.Random; - -public class Board { - private int boardSize; - private int[][] boxes; - int[] geneticSequence; - - - public Board(int boardSize) { - this.boardSize = boardSize; - boxes = new int[boardSize][boardSize]; - geneticSequence = new int[boardSize]; - - initializeBoard(); - } - - public void initializeBoard(){ - for(int i=0; i || - noOfAttacks += countAttackVertical(queenColumnNo); - //right-diagonal search -> \\ - noOfAttacks += countAttackRightDiagonal(queenColumnNo, row); - //left-diagonal search -> // - noOfAttacks += countAttackLeftDiagonal(queenColumnNo, row); - } - - return noOfAttacks/2; - } - - private int countAttackVertical(int queenColumnNo){ - int noOfAttacks=0; - - for(int k=0; k=boardSize){ //not found - startRow += (startColumn-boardSize+1); - startColumn=boardSize-1; - } - for(int m=startRow, n=startColumn; m=0; m++, n--){ - if(boxes[m][n]==1){ - noOfAttacks++; - } - } - - noOfAttacks--; - - return noOfAttacks; - } - - public int findQueen(int row){ - int queenColumnNo=-1; - for(int j=0; j amount){ - strongAmount = amount; - strong = i; - } - } - - if(board[strong].countAttack()==0){ - System.out.println("\n\n\n## SOLVED!!\n***************\n"+board[strong].toString()+"***************"); - break; - } - - board[weak] = board[strong].getCopy(); - - for(int i=0; i=5000){ - System.out.println("\n\n\n## UNSOLVED!!!!!!!"); - } - } - - - public static void main(String[] args) { - Player player = new Player(); - player.startEvolution(); - -// for(int i=0; i<4; i++){ -// System.out.print(player.board[i].toString()); -// System.out.println(player.board[i].countAttack()+"\n\n\n"); -// } - } -} diff --git a/others/huffmanAlgorithm/Extractor.cpp b/others/huffmanAlgorithm/Extractor.cpp deleted file mode 100644 index 7bc2f2f..0000000 --- a/others/huffmanAlgorithm/Extractor.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/** -Name: Minhas Kamal (BSSE-0509, IIT, DU) -Description: This program reads a zip file which ends with '#' & extracts the file. -Date: 21-Oct-2013 -**/ - -#include -#include -#include - -using namespace std; - -ifstream input; //file reader -struct node{ - int value; //value of the node - char info; //character that it contains - bool bit; - node *r, //root - *t1, //left sub tree - *t2; //right sub tree -}; - - -void treeBuilder(int* num, node* tree, int x, int S, int E); //creates the linked tree -void fileExtractor(node* tree, int x); //writes the extracted file - -int main(){ - input.open("huffmanAlgorithm_Input_Zip.txt"); //opening the file - - if(!input.is_open()){ //when the file name is wrong - printf("Sorry the file is not found!"); - input.close(); - return 0; - } - - int S, //the starting char in the ascii table - E; //the ending char in the ascii table - - input >> S >> E ; - //cout << S << " " << E <> num[i]; - //cout << num [i] << " "; ///test - } - //cout << endl; ///test - - int x=(E-S)*2-1; - node tree[x]; - - treeBuilder(num, tree, x, S, E); - - fileExtractor(tree, x); - - input.close(); - - cout << "File Extracted.\n\n"; - - return 0; -} - - -void treeBuilder(int* num, node* tree, int x, int S, int E){ - for(int i=0; i=0){ - lt=i; - break; - } - - for(int i=0; i=0) - if(tree[i].value < tree[lt].value) lt=i; - } - tree[lt].r = &tree[position]; //setting the root of the left sub trees - - - for(int i=0; i=0){ - rt=i; - break; - } - - for(int i=0; i=0) - if(tree[i].value < tree[rt].value) rt=i; - } - tree[rt].r = &tree[position]; //setting the root of the right sub trees - - - tree[lt].bit = false; //setting the bit of the sub trees - tree[rt].bit = true; - - tree[position].value = (tree[lt].value + tree[rt].value); //the value is the sum of the sub trees - tree[position].t1 = &tree[lt]; //setting sub tree of new node - tree[position].t2 = &tree[rt]; - - position++; //increasing the position - } - - - /*/for(int i=0; i> ch; - while(ch!='#'){ //reading the file & counting the characters - node* nod; //for temporary use - nod=&tree[x-1]; //the main root of tree - - while(nod->t1!=NULL){ - //cout << ch; ///test - - if(ch=='0') nod = nod->t1; - else nod = nod->t2; - - input >> ch; - } - fprintf(output, "%c", nod->info); - //cout << nod->info << endl; ///test - } - - fprintf(output, "#"); //indicates the end of file - - fclose(output); - - return ; -} - - diff --git a/others/huffmanAlgorithm/ZipMaker.cpp b/others/huffmanAlgorithm/ZipMaker.cpp deleted file mode 100644 index be06b15..0000000 --- a/others/huffmanAlgorithm/ZipMaker.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/** -Name: Minhas Kamal (BSSE-0509, IIT, DU) -Description: This program reads a text file which ends with '#' & Zips the file. -Date: 21-Oct-2013 -**/ - -#include -#include -#include -#include - -using namespace std; - -#define S 97 //the starting char in the ascii table -#define E 123 //the ending char in the ascii table - - -ifstream input; //file reader -struct node{ - int value; //value of the node - char info; //character that it contains - bool bit; - node *r, //root - *t1, //left sub tree - *t2; //right sub tree -}; - - -void charCounter(int* num); //counts characters in a file -void treeBuilder(int* num, node* tree, int x); //creates the linked tree -void zipFileWriter(int* num, node* tree); - - -int main(){ - int num[E-S]; //holds the number of characters - - charCounter(num); //reading a file & counting the number of different characters - - int x=(E-S)*2-1; - node tree[x]; - - treeBuilder(num, tree, x); - - zipFileWriter(num, tree); - - cout << "Zip file is made.\n"; - - return 0; -} - - - -void charCounter(int* num){ - input.open("huffmanAlgorithm_Input.txt"); //opening the file - - if(!input.is_open()){ //when the file name is wrong - printf("Sorry the file is not found!"); - input.close(); - return ; - } - - for(int i=0; i> ch; - while(ch!='#'){ //reading the file & counting the characters - //cout << ch <<" "; ///test - if(ch>=S && ch> ch; - } - - /*/for(int i=S; i=0){ - lt=i; - break; - } - - for(int i=0; i=0) - if(tree[i].value < tree[lt].value) lt=i; - } - tree[lt].r = &tree[position]; //setting the root of the left sub trees - - - for(int i=0; i=0){ - rt=i; - break; - } - - for(int i=0; i=0) - if(tree[i].value < tree[rt].value) rt=i; - } - tree[rt].r = &tree[position]; //setting the root of the right sub trees - - - tree[lt].bit = false; //setting the bit of the sub trees - tree[rt].bit = true; - - tree[position].value = (tree[lt].value + tree[rt].value); //the value is the sum of the sub trees - tree[position].t1 = &tree[lt]; //setting sub tree of new node - tree[position].t2 = &tree[rt]; - - position++; //increasing the position - } - - - /*/for(int i=0; i mystack; - input >> ch; - while(ch!='#'){ //reading the file once more & writing in the output file - //cout << ch <<" "; ///test - - int i; - for(i=0; ir!=NULL){ //assigning bits in the stack - mystack.push(nod->bit); //bit of the node - nod=nod->r; //assigning the root - } - - - while(!mystack.empty()){ //writing in the output file - //cout << mystack.top(); ///test - //fputc(mystack.top(), output); - fprintf(output, "%d", mystack.top()); - mystack.pop(); - } - //cout << endl; ///test - - input >> ch; //taking the input - } - fprintf(output, "#"); //indicates the end of file - - fclose(output); - input.close(); - - return ; -} - - - -//*/cout << "\nIts all good!!\n"; //debugging unit diff --git a/others/huffmanAlgorithm/huffmanAlgorithm_Input.txt b/others/huffmanAlgorithm/huffmanAlgorithm_Input.txt deleted file mode 100644 index bf49a7f..0000000 --- a/others/huffmanAlgorithm/huffmanAlgorithm_Input.txt +++ /dev/null @@ -1 +0,0 @@ -caaaaaaabbbcdddddeeeeeee# \ No newline at end of file diff --git a/params.json b/params.json new file mode 100644 index 0000000..4a76121 --- /dev/null +++ b/params.json @@ -0,0 +1,6 @@ +{ + "name": "Algorithm Implementations", + "tagline": "Implementation of Elementary Algorithms", + "body": "The project contains algorithms that were implemented in my Data Structure & Algorithms course. Yes, I got marks for those. :sunglasses:\r\n\r\n### Categorical List of Algorithms\r\n\r\nAlgorithmImplementations
\r\n ├─ arithmeticExpressions
\r\n │ ├─ InfixEvaluation
\r\n │ ├─ InfixToPostfix
\r\n │ ├─ InfixToPrefix
\r\n │ ├─ PostfixEvaluation
\r\n │ └─ PrefixEvaluation
\r\n ├─ dataStructures
\r\n │ ├─ listImplementation
\r\n │ │ ├─ implementationUsingNode
\r\n │ │ │ ├─ OneWayLinkedList
\r\n │ │ │ └─ TwoWayLinkedList
\r\n │ │ ├─ OneWayLinkedList
\r\n │ │ └─ TwoWayLinkedList
\r\n │ ├─ stack
\r\n │ │ └─ StackImplementation
\r\n │ ├─ string
\r\n │ │ ├─ String
\r\n │ │ ├─ StringLongestCommonSubSecuence
\r\n │ │ └─ StringLongestIncreasingSubSecuence
\r\n │ └─ tree
\r\n │   ├─ ActivitySelection
\r\n │   ├─ BalanceTree
\r\n │   ├─ KdTree
\r\n │   ├─ BinaryHeap
\r\n │   └─ BinomialTree
\r\n ├─ graph
\r\n │ ├─ BreathFirstSearch
\r\n │ ├─ DepthFirstSearch
\r\n │ ├─ MaxFlow
\r\n │ ├─ ShortestPathAlgorithm
\r\n │ └─ TopologicalSort
\r\n ├─ numericalMethods
\r\n │ ├─ calculus
\r\n │ │ ├─ DerivetivesOnDifferentPoints
\r\n │ │ ├─ IntegrationForwardInterpolation
\r\n │ │ ├─ IntegrationSimpsonRule
\r\n │ │ └─ IntersectingArea
\r\n │ └─ equationSolving
\r\n │   ├─ LinearEquationSolvingProcess
\r\n │   │ ├─ JacobisMethod
\r\n │   │ └─ GaussSeidalMethod
\r\n │   └─ NonLinearEquationSolvingProcess
\r\n │     ├─ BisectionMethod
\r\n │     ├─ FalsePosition
\r\n │     ├─ NewtonRaphson
\r\n │     ├─ FixedPoint
\r\n │     └─ Secant
\r\n ├─ others
\r\n │ ├─ cigaretteSmokersProblem
\r\n │ ├─ geneticAlgorithm
\r\n │ └─ huffmanAlgorithm
\r\n ├─ search
\r\n │ ├─ AStarSearch
\r\n │ ├─ BinarySearch
\r\n │ └─ KnuthMorrisPrattAlgorithm
\r\n ├─ sort
\r\n │ └─ QuickSort
\r\n └─ thread
\r\n   ├─ priorityBased
\r\n   │ ├─ nonpremitive
\r\n   │ └─ premitive
\r\n   └─ shortestJob
\r\n     ├─ nonpremitive
\r\n     └─ premitive
\r\n\r\n### License\r\n\"GNU
This project is licensed under GNU General Public License version-3.\r\n", + "note": "Don't delete this file! It's used internally to help with page regeneration." +} \ No newline at end of file diff --git a/playWithNumbers/factorial/BigFactorials.c b/playWithNumbers/factorial/BigFactorials.c deleted file mode 100644 index 155f5ee..0000000 --- a/playWithNumbers/factorial/BigFactorials.c +++ /dev/null @@ -1,56 +0,0 @@ -/** -*Name: Minhas Kamal (BSSE-0509, IIT, DU) -*Date: 27.Dec.13 -**/ - -#include - -#define DIGIT 1000000 - -int main() -{ - while(1) - { - short int a[DIGIT+1]; - int x, i; - for(i=0; i0; j--) - { - a[j]=i%10; - i=i/10; - } - - int k=0; - for(i=x-1; i>0; i--) - { - for(j=DIGIT; a[j]>=0; j--) - { - k=(i*a[j])+k; - a[j]=k%10; - k=k/10; - } - - a[j]=k%10; - k=k/10; - a[j-1]=k; - - for(k=0; a[k]<1; k++) a[k]=-1; - k=0; - } - - - for(i=0; a[i]<1; i++); - for(; i - -int main() -{ - for(; ; ) - { - int a[785], x, i; - for(i=0; i<785; i++) a[i]=-1; - scanf("%d", &x); - if(x<1 || x>366) break; - - int j; - i=x; - for(j=784; i>0; j--) - { - a[j]=i%10; - i=i/10; - } - - int k=0; - for(i=x-1; i>0; i--) - { - for(j=784; a[j]>=0; j--) - { - k=(i*a[j])+k; - a[j]=k%10; - k=k/10; - } - a[j]=k%10; - k=k/10; - a[j-1]=k; - - for(k=0; a[k]<1; k++) a[k]=-1; - k=0; - } - - int num[10]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - - for(i=0; i<10; i++) - for(j=0; j<785; j++) - if(i==a[j]) num[i]++; - - printf("%d! --\n", x); - printf(" (0)%5d (1)%5d (2)%5d (3)%5d (4)%5d\n", num[0], num[1], num[2], num[3], num[4]); - printf(" (5)%5d (6)%5d (7)%5d (8)%5d (9)%5d \n", num[5], num[6], num[7], num[8], num[9]); - } - - return 0; -} diff --git a/playWithNumbers/factorial/FactorsOfFactorial.c b/playWithNumbers/factorial/FactorsOfFactorial.c deleted file mode 100644 index f15adea..0000000 --- a/playWithNumbers/factorial/FactorsOfFactorial.c +++ /dev/null @@ -1,79 +0,0 @@ -/** -*Name: Minhas Kamal (BSSE-0509, IIT, DU) -*Date: 12.May.13 -**/ - -#include - -void varify(int x); - -int n[25]; - -int main() -{ - for(; ; ) - { - int p; - for(p=0; p<25; p++) n[p]=0; - - int i, j; - scanf("%d", &i); - if(i==0) break; - if(i>100 || i<2) continue; - - - for(j=2; j<=i; j++) varify(j); - - for(j=24; n[j]==0; j--); - - printf("%3d! =", i); - - for(i=0; i<=j; i++) - { - printf("%3d", n[i]); - - if((i+1)%15==0) printf("\n "); - } - printf("\n"); - } - - - return 0; -} - -void varify(int x) -{ - int d=x; - while(d%2==0) - { - n[0]++; - d=d/2; - } - - int a, b, c=1; - for(a=3; a<=x; a=a+2) - { - int z=1; - for (b=3; b<=a/3; b=b+2) - { - if(a%b==0) - { - z=0; - break; - } - } - if(z==1) - { - d=x; - while(d%a==0) - { - n[c]++; - d=d/a; - } - c++; - } - } - return ; -} - - diff --git a/playWithNumbers/fibonaciiNumber/FibonaciiNumber.c b/playWithNumbers/fibonaciiNumber/FibonaciiNumber.c deleted file mode 100644 index 31cdf13..0000000 --- a/playWithNumbers/fibonaciiNumber/FibonaciiNumber.c +++ /dev/null @@ -1,30 +0,0 @@ -/** -*Name: Minhas Kamal (IIT, DU) -*Date:24.Feb.2013 -**/ - -#include - -int main() { - int a; - - printf("Enter number: "); - scanf("%d", &a); - - long long int n, x = 0, y = 1, z; - - for (n = 1; n < a; n++) { - z = y; - y = x + y; - x = z; - if (x < 0) { - printf("...\n...\nCannot calculate more than %lld!\n...\n...\n", n); - return 0; - } - } - - printf("The num is: %lld\n\n", x); - - return 0; -} - diff --git a/playWithNumbers/fibonaciiNumber/FibonaciiSerise.c b/playWithNumbers/fibonaciiNumber/FibonaciiSerise.c deleted file mode 100644 index 00b89c7..0000000 --- a/playWithNumbers/fibonaciiNumber/FibonaciiSerise.c +++ /dev/null @@ -1,38 +0,0 @@ -/** -*Name: Minhas Kamal (IIT, DU) -*Date:24.Feb.2013 -**/ - -#include - -int main() { - int a, b; - - printf("Enter first serial num: "); - scanf("%d", &a); - - printf("Enter second serial num: "); - scanf("%d", &b); - - int m, n; - - for (m = a; m <= b; m++) { - long long int x = 0, y = 1, z; - - for (n = 1; n < m; n++) { - z = y; - y = x + y; - x = z; - } - if (x < 0) { - printf("...\n...\nCannot calculate more!\n...\n...\n"); - return 0; - } - - else - printf("%dth num is: %lld\n", m, x); - } - - return 0; -} - diff --git a/playWithNumbers/fibonaciiNumber/FibonaciiSum.c b/playWithNumbers/fibonaciiNumber/FibonaciiSum.c deleted file mode 100644 index ecb333c..0000000 --- a/playWithNumbers/fibonaciiNumber/FibonaciiSum.c +++ /dev/null @@ -1,29 +0,0 @@ -/** -*Name: Minhas Kamal (IIT, DU) -*Date:24.Feb.2013 -**/ - -#include - -int main() { - int a; - - printf("Enter number: "); - scanf("%d", &a); - - long long int n, x = 0, y = 1, z, sum = 0; - - for (n = 1; n < a; n++) { - sum = sum + y; - z = y; - y = x + y; - x = z; - if (sum < y) { - printf("...\n...\nCannot calculate more than %lld!\n...\n...\n", n); - return 0; - } - } - printf("Sum is: %lld\n\n", sum); - - return 0; -} diff --git a/playWithNumbers/otherNumbers/FriendNumbers.c b/playWithNumbers/otherNumbers/FriendNumbers.c deleted file mode 100644 index 76876b8..0000000 --- a/playWithNumbers/otherNumbers/FriendNumbers.c +++ /dev/null @@ -1,53 +0,0 @@ -/** -*Name: Minhas Kamal -*Date:04.May.2013 -**/ - -#include - - -int main() -{ - long int a, b, a1, b1; - printf("Enter two positive integers: "); //asking the user - scanf("%ld %ld", &a, &b); - a1=a; //to store the main value - b1=b; //to store the main value - - if(a<1 || b<1) //input check - { - printf("Invalid input!"); - exit(1); - } - - for( ; ; ) //main operation for first integer - { - int af=0; - for( ; a>10; a=a/10) - { - af=af+(a%10); - } - af=af+a; - a=af; - if(a<10) break; //breaking the loop - } - - for( ; ; ) //main operation for second integer - { - int bf=0; - for( ; b>10; b=b/10) - { - bf=bf+(b%10); - } - bf=bf+b; - b=bf; - if(b<10) break; //breaking the loop - } - - if(a==b) printf("%ld and %ld are friends\n", a1, b1); //output - else printf("%ld and %ld are not friends\n", a1, b1); - - return 0; -} - - diff --git a/playWithNumbers/otherNumbers/PerfectNumberHaunting.c b/playWithNumbers/otherNumbers/PerfectNumberHaunting.c deleted file mode 100644 index d3f379c..0000000 --- a/playWithNumbers/otherNumbers/PerfectNumberHaunting.c +++ /dev/null @@ -1,35 +0,0 @@ -/** -*Name: Minhas Kamal -*Date:02.Jan.2014 -**/ - -#include - -int main() -{ - long long int s; - printf("Enter the starting number: "); - scanf("%lld", &s); - - long long int f; - printf("Enter the finishing number: "); - scanf("%lld", &f); - - long long int a, b; - - for(a=s ; a<=f; a++) - { - if(a%2!=0) continue; - - long long int c=0; - for(b=1; b<=(a/3); b++) - { - if(a%b==0) c=c+b; - } - if(a/2==c) printf("%lld, ", a); - } - - getchar(); getchar(); - - return 0; -} diff --git a/playWithNumbers/pascalTriangle/BetterPascalTriangle.c b/playWithNumbers/pascalTriangle/BetterPascalTriangle.c deleted file mode 100644 index a0530ee..0000000 --- a/playWithNumbers/pascalTriangle/BetterPascalTriangle.c +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Name: Minhas Kamal (DU,IIT) -* Date: 09.Apr.13 -**/ - -#include - -int main() -{ - int l; - printf("Enter number of lines: "); - scanf("%d", &l); - - int z, *p[100]; - *p=0; - *(p+1)=1; - *(p+2)=0; - - for(z=1; z<=l; z++) - { - int i, j, t; - - for(i=0; i - -int main() -{ - int a[50][50], x, i,j; - - printf("Enter the number of rows: "); - scanf("%d", &x); - - for(i=0;i<=x;i++) - { - for(j=0;j0;j--) - printf(" "); - - for(j=0;j - -int num (int x, int y); -long long int factorial (int z); - -int main () -{ - int l; - - printf("Enter number of lines: "); - scanf("%d", &l); - printf("\n\n\n\n"); - - int a, b, c; - - for(a=0; a0; b--)printf(" "); - for(c=0; c<=a; c++){ - int r = num (a, c); - printf("%d ", r); - } - printf("\n"); - } - printf("\n\n\n\n"); - - return 0; -} - -int num (int x, int y) -{ - long long int m = factorial(x); - long long int n = factorial(y); - long long int o = factorial(x-y); - - int p = m/(n*o); - - return (p); -} - -long long int factorial (int z) -{ - int a; - long long int b=1; - for(a=1; a<=z; a++) b=b*a; - - return (b); -} diff --git a/playWithNumbers/pascalTriangle/Piramid.c b/playWithNumbers/pascalTriangle/Piramid.c deleted file mode 100644 index 734d2ea..0000000 --- a/playWithNumbers/pascalTriangle/Piramid.c +++ /dev/null @@ -1,26 +0,0 @@ -/** -* Name: Minhas Kamal (DU,IIT) -* Date: 22.Feb.13 -**/ - -#include - -int main () -{ - int l; - - printf("Enter number of lines: "); - scanf("%d", &l); - - int a, b, c; - - for(a=0; a<=l; a++){ - for(b=l-a; b>0; b--)printf(" "); - for(c=0; c<(2*a)-1; c++)printf("|"); - printf("\n"); - } - - return 0; -} - - diff --git a/playWithNumbers/pascalTriangle/RealPascalTriangle.c b/playWithNumbers/pascalTriangle/RealPascalTriangle.c deleted file mode 100644 index 7482567..0000000 --- a/playWithNumbers/pascalTriangle/RealPascalTriangle.c +++ /dev/null @@ -1,68 +0,0 @@ -/** -* Name: Minhas Kamal (DU,IIT) -* Date: 09.Apr.13 -**/ - -#include - -long int num (int x, int y); -unsigned long long int factorial (int z); - -int main () -{ - int l; - - printf("Enter number of lines: "); - scanf("%d", &l); - if(l<1) {printf("Wrong input!"); return 0;} - - printf("\n\n\n\n"); - - int a, b, c; - - for(a=0; a0; b--)printf(" "); - for(c=0; c<=a; c++) - { - long int r = num (a, c); - //printf("%d ", r); - - if(r<1) {printf("\n\n**** Memory Error! ****\n\n"); return 0;} - else if(r<10) printf(" %d ", r); - else if(r<100) printf(" %d ", r); - else if(r<1000) printf(" %d ", r); - else if(r<10000) printf(" %d ", r); - else if(r<100000) printf(" %d ", r); - else if(r<1000000) printf(" %d ", r); - else if(r<10000000) printf(" %d", r); - else if(r>=10000000) printf("%d", r); - - } - printf("\n\n\n"); - } - printf("\n\n\n\n"); - - return 0; -} - -long int num (int x, int y) -{ - unsigned long long int m = factorial(x); - unsigned long long int n = factorial(y); - unsigned long long int o = factorial(x-y); - - long int p = m/(n*o); - - return (p); -} - -unsigned long long int factorial (int z) -{ - int a; - unsigned long long int b=1; - for(a=1; a<=z; a++) b=b*a; - - return (b); -} - diff --git a/playWithNumbers/primeNumber/AnotherWayOfPrimeNumberHaunting.c b/playWithNumbers/primeNumber/AnotherWayOfPrimeNumberHaunting.c deleted file mode 100644 index 60fe802..0000000 --- a/playWithNumbers/primeNumber/AnotherWayOfPrimeNumberHaunting.c +++ /dev/null @@ -1,51 +0,0 @@ -/** -* Name: Minhas Kamal -* Occupation: Student (DU,IIT) -* Date: Apr.13 -**/ - -#include - -void varify (long int m, long int n); - -int main () -{ - long int s,f; //starting & finishing number - - printf ("Enter your starting number: "); - scanf ("%ld", &s); - - printf ("Enter your finishing number: "); - scanf ("%ld", &f); - - if (s>f) printf("Wrong information!\a\nstarting number is bigger.\a\n"); - else if (s<2 || f<3) printf ("\aError!\a"); - - else{ - printf("\nThe first prime is: 2\nYour requirements are given bellow:\n\n"); - varify (s,f); - } - printf("\n\n"); - - return 0; -} - - -void varify (long int m, long int n) //all works are done here -{ - long int w; - if(m%2==0) w=(m+1); - else w=m; - - for(m=w; m<=n; m=m+2){ - long int y, z=1; - for (y=3; y<=m/3; y=y+2){ - if(m%y==0) z=0; - } - if (z==1)printf("%ld,\t",m); - } - - return ; -} - - diff --git a/playWithNumbers/primeNumber/DefinitePrimeNumberHaunting.c b/playWithNumbers/primeNumber/DefinitePrimeNumberHaunting.c deleted file mode 100644 index 1df0841..0000000 --- a/playWithNumbers/primeNumber/DefinitePrimeNumberHaunting.c +++ /dev/null @@ -1,81 +0,0 @@ -/** -*Name: Minhas Kamal -*Occupation: Student (DU,IIT) -*Date: 16.May.13 -**/ - -#include -#include -#include - -int main () -{ - clock_t start, finish; - - long long int a, b; //domain - printf("Enter your starting number: "); - scanf("%lld", &a); - printf("Enter your finishing number: "); - scanf("%lld", &b); - - int k, s; - printf("Enter your number of primes: "); - scanf("%d", &k); - printf("Enter the distance: "); - scanf("%d", &s); - printf("\n"); - - if(a>b) exit(1); - long long int tup[k]; - - start = clock(); - - int i; - for(i=0; i - -int main () -{ - for( ; ; ) - { - long long int x; - printf ("Enter your number: "); - scanf ("%lld", &x); - - if(x<=0) - { - printf("\aError!\a\a"); - return 0; - } - printf("\n\n"); - - long long int y; - int z=1; - - for (y=2; y<=x/2; y++) - { - if (x%y==0) { printf ("%lld, ", y); z=0;} - } - - if(z==1) printf("\aThis is a prime number.\a"); - - printf("\n\n"); - - int d=1; - printf("Do you want to continue? 1(y) 0(n)."); - scanf(" %d", &d); - if(!d) break; - } - - return 0; -} diff --git a/playWithNumbers/primeNumber/GreatPrimeNumberHaunting.c b/playWithNumbers/primeNumber/GreatPrimeNumberHaunting.c deleted file mode 100644 index 0626780..0000000 --- a/playWithNumbers/primeNumber/GreatPrimeNumberHaunting.c +++ /dev/null @@ -1,74 +0,0 @@ -/** -* Name: Minhas Kamal -* Occupation: Student (DU,IIT) -* Date: 16.May.13 -**/ - -#include -#include -#include - -int main () -{ - clock_t start, finish; - - unsigned long long int s, f; //starting & finishing number - - printf ("Enter your starting number: "); - scanf ("%lld", &s); - - printf ("Enter your finishing number: "); - scanf ("%lld", &f); - - start = clock(); - - if (s>f) printf("Wrong information!\a\nstarting number is bigger.\a\n"); //starting number should be smaller than finishing number - else if (s<1 || f<2) printf ("\aError!\a"); //I have done this to save more time - - else - { - if(s%2==0) s=(s+1); //I have made starting number odd, this will save time - - unsigned long long int x; //holds & increases starting num's value - long long int y, y2; //y is the factorial of x & y2 contains square root of x - char a=0; //to arrange lines - char z; //here z is the flag - - printf("\nThe first prime is: 2\nYour requirements are given bellow:\n\n"); - - for(x=s; x<=f; x=x+2) //the program will work only with odd numbers - { - y2=sqrt(x); - z=1; - - for (y=3; y<=y2; y=y+2) //verification loop - { - if(x%y==0) - { - z=0; - break; - } - } - - if (z==1) //printing - { - printf("%lld,\t",x); - a++; - - if(a%10==0) - { - printf("\n"); - a=0; - } - } - } - printf("\n\n"); - } - - finish = clock(); - printf("TIME: %d.%.3d sec \n\n", (finish-start)/1000, (finish-start)%1000); - - return 0; -} - - diff --git a/playWithNumbers/primeNumber/GreatestPrimeNumberHaunting.c b/playWithNumbers/primeNumber/GreatestPrimeNumberHaunting.c deleted file mode 100644 index a61ccf1..0000000 --- a/playWithNumbers/primeNumber/GreatestPrimeNumberHaunting.c +++ /dev/null @@ -1,150 +0,0 @@ -/** -* Name: Minhas Kamal -* Occupation: Student (DU,IIT) -* Date: May.13 -* Comment: I have tried to make this program more time efficient, but at the same -* time more complex. It finds all prime number in its domain (3 - 18,446,744,073,709,551,616). -**/ - -#include -#include -#include - -int main () -{ - clock_t st, fn; - - long long int s,f; //starting & finishing number - - printf ("Enter your starting number: "); - scanf ("%lld", &s); - - printf ("Enter your finishing number: "); - scanf ("%lld", &f); - - st=clock(); - - if (s>f) - { //Starting number is smaller than finishing number - long long int temp = s; - s=f; - f=temp; - } - - if (s<2) - { - s=2; - } - - if(f<3) - { - f=3; - } - - else - { - printf("\n\n##Prime numbers are:\n\n"); - if(s<3){ - printf("2,\t"); - } - - long long int x, w; - - if(s%2==0) w=(s+1); //I have made starting number odd, this will save time - else w=s; - - for(x=w; x<=f; x=x+2) //The program will work only with odd numbers - { - int z=1; //Here z is the flag - long long int y; - - if(x>500) - { - if(x%3 == 0) z=0; - else if(x%5 == 0) z=0; - else if(x%7 == 0) z=0; - else if(x%11 == 0) z=0; - else if(x%13 == 0) z=0; - else if(x%17 == 0) z=0; - else if(x%19 == 0) z=0; - else if(x%23 == 0) z=0; - else if(x%29 == 0) z=0; - else if(x%31 == 0) z=0; - else if(x%37 == 0) z=0; - else if(x%41 == 0) z=0; - else if(x%43 == 0) z=0; - else if(x%47 == 0) z=0; - - else if(x%53 == 0) z=0; - else if(x%59 == 0) z=0; - else if(x%61 == 0) z=0; - else if(x%67 == 0) z=0; - else if(x%71 == 0) z=0; - else if(x%73 == 0) z=0; - else if(x%79 == 0) z=0; - else if(x%83 == 0) z=0; - else if(x%89 == 0) z=0; - else if(x%97 == 0) z=0; - - else if(x%101 == 0) z=0; - else if(x%103 == 0) z=0; - else if(x%107 == 0) z=0; - else if(x%109 == 0) z=0; - else if(x%113 == 0) z=0; - else if(x%127 == 0) z=0; - else if(x%131 == 0) z=0; - else if(x%137 == 0) z=0; - else if(x%139 == 0) z=0; - else if(x%149 == 0) z=0; - - else if(x%151 == 0) z=0; - else if(x%157 == 0) z=0; - else if(x%163 == 0) z=0; - else if(x%167 == 0) z=0; - else if(x%173 == 0) z=0; - else if(x%179 == 0) z=0; - else if(x%181 == 0) z=0; - else if(x%191 == 0) z=0; - else if(x%193 == 0) z=0; - else if(x%197 == 0) z=0; - else if(x%199 == 0) z=0; - - else if(x%211 == 0) z=0; - else if(x%223 == 0) z=0; - else if(x%227 == 0) z=0; - else if(x%229 == 0) z=0; - else if(x%233 == 0) z=0; - else if(x%239 == 0) z=0; - else if(x%241 == 0) z=0; - - else if(x%251 == 0) z=0; - else if(x%257 == 0) z=0; - - else for (y=263; y<=sqrt(x); y=y+2) - { - if(x%y == 0) {z=0; break;} - } - } - - else for(y=3; y<=x/3; y=y+2) {if(x%y == 0) z=0;} - - - if(x -#include - -const int size=100000000; -int ara[100000000]; - -void print_ara() -{ - int i; - for(i=2; i=size) - { - printf("The number should be less than %d\n", size); - continue; - } - - if(1==is_prime(n)) printf("%d is a prime number.\n", n); - - else printf("%d is not a prime number.\n", n); - } - return 0; -} diff --git a/playWithNumbers/primeNumber/PrimeNumberHaunting.asm b/playWithNumbers/primeNumber/PrimeNumberHaunting.asm deleted file mode 100644 index 52c4e34..0000000 --- a/playWithNumbers/primeNumber/PrimeNumberHaunting.asm +++ /dev/null @@ -1,68 +0,0 @@ -##Writer: Minhas Kamal -##Date: 01-MAY-2014 -##Function: Finds prime numbers in a certain range. - -#####**data**##### -.data - -prompt: .asciiz "Enter your range: " -new_line: .asciiz "\n" - -#####**text**##### -.text - -main: - la $a0, prompt #prompt for user input - li $v0, 4 - syscall - - li $v0, 5 #take start integer - syscall - add $t1, $v0, $zero - - li $t0, 2 #see if divisible by 2 or not (even or odd) - div $t4, $t1, $t0 - mul $t4, $t4, $t0 - bne $t4, $t1, odd - addi $t1, $t1, 1 #if even make odd -odd: - - li $v0, 5 #take stop integer - syscall - add $t2, $v0, $zero - - - addi $t3, $t1, -2 #loop controller -loop_1: - addi $t3, $t3, 2 - - ble $t3, 1, loop_1 #loopback when <=1 is inputted - beq $t3, 3, isPrime #when 3 is inputted - bgt $t3, $t2, exit #when >$t2 exit - - li $t0, 3 #loop controller #starts from 3 to last - div $t4, $t3, $t0 -loop_2: - div $t4, $t3, $t0 #see if divisible or not - mul $t4, $t4, $t0 - beq $t4, $t3, isNotPrime - - addi $t0, $t0, 2 #continue the loop - blt $t0, $t4, loop_2 - -isPrime: - add $a0, $t3, $zero - li $v0, 1 - syscall - la $a0, new_line - li $v0, 4 - syscall - j loop_1 - -isNotPrime: - j loop_1 - - -exit: - li $v0, 10 - syscall diff --git a/playWithNumbers/primeNumber/PrimeNumberHaunting.c b/playWithNumbers/primeNumber/PrimeNumberHaunting.c deleted file mode 100644 index 89fd42e..0000000 --- a/playWithNumbers/primeNumber/PrimeNumberHaunting.c +++ /dev/null @@ -1,30 +0,0 @@ -/** -* Name: Minhas Kamal -* Occupation: Student (DU,IIT) -* Date: Apr.13 -**/ - -#include - -int main () -{ - long int l; - printf("Enter your limit: "); - scanf("%ld", &l); - - long int x; - printf("2,\t"); - for(x=3; x<=l; x=x+2){ - long int y; - int z=1; - - for (y=3; y<=x/3; y=y+2){ - if(x%y==0) - z=0; - } - if (z==1) - printf("%ld,\t",x); - } - - return 0; -} diff --git a/playWithNumbers/time/AgeCalculator.c b/playWithNumbers/time/AgeCalculator.c deleted file mode 100644 index c9d0621..0000000 --- a/playWithNumbers/time/AgeCalculator.c +++ /dev/null @@ -1,34 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 18-Aug-2013 -**/ - -// Age Calculator - -#include - -int main () -{ - int bd, bm, by; - printf("Enter your birth day (dd. mm. yy): "); - scanf("%d %d %d", &bd, &bm, &by); - - int td, tm, ty; - printf("\nEnter today's date (dd. mm. yy): "); - scanf("%d %d %d", &td, &tm, &ty); - - int d, a=0; - if(td - -int main() -{ - for(; ; ) - { - int y; - printf("Enter your year: "); - scanf("%d", &y); - - if(y%400==0) printf("%d is a leap year.\n", y); - else if(y%100==0) printf("%d is not a leap year.\n", y); - else if(y%4==0) printf("%d is a leap year.\n", y); - else printf("%d is not a leap year.\n", y); - - char ch; - printf("Press 'c' to continue.\n"); - fflush(stdin); - scanf("%c", &ch); - - printf("\n"); - - if(ch!='c' && ch!='C') break; - } - - return 0; -} diff --git a/playWithNumbers/time/Stopwatch.c b/playWithNumbers/time/Stopwatch.c deleted file mode 100644 index 33a6368..0000000 --- a/playWithNumbers/time/Stopwatch.c +++ /dev/null @@ -1,45 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: Aug-2013 -**/ - -#include -#include - -int main() -{ - printf("*#This is a stopwatch#*\n\n\n"); - printf("**Press 'p' to pause.\n"); - printf("**Press any key to start & to stop."); - getch(); - system("cls"); - printf("\t\t*#This is a stopwatch#*\n\n\n"); - - clock_t s, n; - s = clock(); - - while(1){ - while(1){ - n=clock(); - printf("\r"); - printf("Time-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000); - if(kbhit()) break; //kbhit() does not read the character - } - - if(getch()=='p'){ - printf("\rTime-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000); - getch(); - } - else break; - - s=s+(clock()-n); //split time - //s=clock(); //lap time - } - - printf("\rTime-\t %d : %d : %d ", ((n-s)/1000)/60, ((n-s)/1000)%60, (n-s)%1000); - - getch(); getch(); //to read the extra characters - printf("\n\n\n"); - - return 0; -} diff --git a/playWithNumbers/time/TimeAfter.c b/playWithNumbers/time/TimeAfter.c deleted file mode 100644 index c439fd3..0000000 --- a/playWithNumbers/time/TimeAfter.c +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: Sep-2013 -**/ - -#include - -int main () -{ - int s, m, h, p; - printf("Enter current time (hh. mm. ss): "); - scanf("%d %d %d", &h, &m, &s); - printf("Is it 1='am' or 2='pm'? "); - scanf("%d", &p); - - int as, am, ah; - printf("Enter addition (hh. mm. ss): "); - scanf("%d %d %d", &ah, &am, &as); - - int a, x=0; - if(s+as >= 60){a=s+as-60; x=1;} - else a=s+as; - - int b, y=0; - if(m+am+x >= 60){b=m+am-60+x; y=1;} - else b=m+am+x; - - int c = (h+ah+y)%12 + 1; - - - printf("\nThe time will be: %d. %d. %d", c, b, a); - - if((h+ah+y)%24 < 12){ - if(p==1) p=2; - else p=1; - } - - if(p==1)printf(" am\n\n"); - else printf(" pm\n\n"); - - return 0; -} - diff --git a/search/aStarSearch/AStarSearch.java b/search/aStarSearch/AStarSearch.java deleted file mode 100644 index b537dcc..0000000 --- a/search/aStarSearch/AStarSearch.java +++ /dev/null @@ -1,191 +0,0 @@ -/** -* Developer: Minhas Kamal (BSSE-0509, IIT, DU) -* Date: 06.Sep.2015 -* Comment: This piece of program solves 8 puzzle problem using A* search algorithm. -**/ - -package eightPuzzle; - -import java.util.Random; - -public class AStarSearch { - int SWAP_WITH_TOP=0, SWAP_WITH_RIGHT=1, SWAP_WITH_BOTTOM=2, SWAP_WITH_LEFT=3; - - int numberOfBoxsInRow = 3; - int numberOfBoxs = numberOfBoxsInRow*numberOfBoxsInRow; // only block 0 has the capability to swap with others. - - int[] box; - - AStarSearch(){ - box = new int[numberOfBoxs]; - - initialize(); - } - - //////////////////////////////////////////////////////////////////////////////// - - private void initialize(){ - System.out.println("##\t\tINITIALIZING"); - - for(int i=0; i0 && cyclesrecentHeuristics){ - heuristics=recentHeuristics; - swapDirection = i; - } - } - } - - if(swapDirection == SWAP_WITH_BOTTOM){ - frobiddenSwapDirection = SWAP_WITH_TOP; - }else if(swapDirection == SWAP_WITH_TOP){ - frobiddenSwapDirection = SWAP_WITH_BOTTOM; - }else if(swapDirection == SWAP_WITH_LEFT){ - frobiddenSwapDirection = SWAP_WITH_RIGHT; - }else{ - frobiddenSwapDirection = SWAP_WITH_LEFT; - } - - swap(box, swapDirection); - System.out.println("# Heuristics: "+heuristics); - printBlocks(); - - cycles++; - } - } - - public int[] clone(int[] box){ - int[] boxClone = new int[box.length]; - for(int i=0; i=numberOfBoxs){ - return false; - } - - int temp = box[zeroBoxIndex]; - box[zeroBoxIndex] = box[swapBoxIndex]; - box[swapBoxIndex] = temp; - - return true; - } - - public int calculateHeuristics(int[] box){ - int heuristics = 0; - int numericalDifference, columnDifference, rowDifference, totalDiference; - - for(int i=0; i -#include - -using namespace std; - -int main() -{ - ifstream list; //input file stream - list.open("BinarySearch_Input.txt"); - //list.open(argv[1]); - - if(!list.is_open()){ //when file is not found - cout << "File is not found!\n"; - return 0; - } - - int member; //number of integers - list >> member; - - int myArray[member]; //stores the input data - for(int i=0; i> myArray[i]; - - ///BinarySearch - int element; - cout << "Enter the element: "; - cin >> element; - - int left=0, //left location of the myArray - right=member-1, //right location of the myArray - location=-1; //the location of the element - - while(right-left > 0){ - int loc = (right+left)/2; - - if(myArray[loc]==element){ - location=loc; - break; - } - else if(myArray[loc]>element){ - right = loc-1; - } - else if(myArray[loc] -#include -#include - -using namespace std; - - -int KMPAlgorithm(string wholeFileString, string subFileString); -void FailureFunction(string subFileString, int* F); - - -int main(int argc, char *argv[]){ - //**taking the file name - string fileName=""; - if(argc>1){ - fileName=argv[1]; - }else{ - cout << "Enter the file name: "; - cin >> fileName; - //fileName="KMPInput.txt";//test - } - - - //**opening the file - ifstream input; - input.open(fileName.c_str()); - if(!input.is_open()){ //when the file name is wrong - printf("Sorry the file is not found!"); - input.close(); - return 1; - } - - - //**reading file - string wholeFileString=""; - string subString=""; - input >> wholeFileString; - while(!input.eof()){ - input >> subString; - - wholeFileString.append(" "+subString); - } - //cout << wholeFileString;//test - input.close(); - - - //**taking the input of sub string - string subFileString=""; - cout << "Enter your sub string: "; - cin >> subFileString; - //cout << subFileString;//test - - - //**finding the position of sub string - int startPosition=-1; - - //KMP Algorithm - if(subFileString.length()<=wholeFileString.length()){ - startPosition=KMPAlgorithm(wholeFileString, subFileString); - }else{ - startPosition=-2; - } - - - //**position output - if(startPosition==-2){ - cout << "The sub string is larger!\n\n"; - }else if(startPosition==-1){ - cout << "The sub string is not found!\n\n"; - }else{ - cout << "The position of the sub string is: " << ++startPosition << "\n\n"; - } - - - return 0; -} - - -//searching algorithm -int KMPAlgorithm(string wholeFileString, string subFileString){ - int position=-1; - - int wholeFileStringLength=wholeFileString.length(), - subFileStringLength=subFileString.length(); - - int F[subFileStringLength]; - FailureFunction(subFileString, F); - - /*///test - int k=0; - for(; k0 && subFileString[j]!=wholeFileString[i]){ - j=F[j-1]; - } - - if(subFileString[j]==wholeFileString[i]){ - j++; - } - - if(j==subFileStringLength){ - position=i-subFileStringLength+1; - break; - } - } - - - return position; -} - -//failure function -void FailureFunction(string String, int* F){ - int StringLength=String.length(); - int value=0; - F[0]=value; - - int i; - for(i=1; i0 && String[value]!=String[i]){ - value=F[value-1]; - } - - if(String[value]==String[i]){ - value=value+1; - } - - F[i]=value; - } - - - return; -} - - - diff --git a/search/knuthMorrisPrattAlgorithm/KnuthMorrisPrattAlgorithm_Input.txt b/search/knuthMorrisPrattAlgorithm/KnuthMorrisPrattAlgorithm_Input.txt deleted file mode 100644 index 3e3ffef..0000000 --- a/search/knuthMorrisPrattAlgorithm/KnuthMorrisPrattAlgorithm_Input.txt +++ /dev/null @@ -1 +0,0 @@ -C was invented and first implemented by Dennis Ritchie on a DEC PDP-11 that used the Unix operating system. C is the result of a development process that started with an older language called BCPL. BCPL was developed by Martin Richards, and it influenced a language called B, which was invented by Ken Thompson. B led to the development of C in the 1970s. \ No newline at end of file diff --git a/sort/quickSort/QuickSort.cpp b/sort/quickSort/QuickSort.cpp deleted file mode 100644 index 5640113..0000000 --- a/sort/quickSort/QuickSort.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/** -* Programmer: Minhas Kamal (BSSE0509,IIT,DU) -* Date: 15-Nov-2013 -**/ - -#include -#include - -using namespace std; - -void quickSort(int *myArray, int left, int right); //sorts the list -int qSort(int *myArray, int left, int right); //swaps & places one element at right place - -int main() -{ - ifstream list; //input file stream - list.open("QuickSort_Input.txt"); - //list.open(argv[1]); - - if(!list.is_open()){ //when file is not found - cout << "File is not found!\n"; - return 0; - } - - int member; //number of integers - list >> member; - - int myArray[member]; //stores the input data - for(int i=0; i> myArray[i]; - - int left=0, right=member-1; - - if(member>1) - quickSort(myArray, left, right); - - - for(int i=0; imyArray[right]){ - int temp=myArray[lock]; //swapping - myArray[lock]=myArray[right]; - myArray[right]=temp; - - lock=right; - } - - while(myArray[left]<=myArray[lock] && lock!=left) //searching from left to right - left++; - if(lock==left) break; - if(myArray[left]>myArray[lock]){ - int temp=myArray[lock]; //swapping - myArray[lock]=myArray[left]; - myArray[left]=temp; - - lock=left; - } - } - return lock; -} diff --git a/sort/quickSort/QuickSort_Input.txt b/sort/quickSort/QuickSort_Input.txt deleted file mode 100644 index 6b95d7c..0000000 --- a/sort/quickSort/QuickSort_Input.txt +++ /dev/null @@ -1,11 +0,0 @@ -100 -19 34 29 67 37 90 99 89 45 56 -64 73 85 21 38 23 57 18 94 36 -67 67 45 45 78 67 65 78 56 71 -56 45 60 45 64 70 65 76 85 69 -54 50 39 45 90 69 57 65 71 65 -78 45 61 54 60 53 68 54 70 65 -79 40 56 34 58 39 59 46 43 70 -68 76 88 99 97 100 67 84 89 82 -81 79 74 12 11 15 100 99 56 34 -26 33 98 96 94 97 93 29 100 98 diff --git a/stylesheets/github-light.css b/stylesheets/github-light.css new file mode 100644 index 0000000..d64ba5d --- /dev/null +++ b/stylesheets/github-light.css @@ -0,0 +1,124 @@ +/* +The MIT License (MIT) + +Copyright (c) 2015 GitHub, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +.pl-c /* comment */ { + color: #969896; +} + +.pl-c1 /* constant, markup.raw, meta.diff.header, meta.module-reference, meta.property-name, support, support.constant, support.variable, variable.other.constant */, +.pl-s .pl-v /* string variable */ { + color: #0086b3; +} + +.pl-e /* entity */, +.pl-en /* entity.name */ { + color: #795da3; +} + +.pl-s .pl-s1 /* string source */, +.pl-smi /* storage.modifier.import, storage.modifier.package, storage.type.java, variable.other, variable.parameter.function */ { + color: #333; +} + +.pl-ent /* entity.name.tag */ { + color: #63a35c; +} + +.pl-k /* keyword, storage, storage.type */ { + color: #a71d5d; +} + +.pl-pds /* punctuation.definition.string, string.regexp.character-class */, +.pl-s /* string */, +.pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, +.pl-sr /* string.regexp */, +.pl-sr .pl-cce /* string.regexp constant.character.escape */, +.pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */, +.pl-sr .pl-sre /* string.regexp source.ruby.embedded */ { + color: #183691; +} + +.pl-v /* variable */ { + color: #ed6a43; +} + +.pl-id /* invalid.deprecated */ { + color: #b52a1d; +} + +.pl-ii /* invalid.illegal */ { + background-color: #b52a1d; + color: #f8f8f8; +} + +.pl-sr .pl-cce /* string.regexp constant.character.escape */ { + color: #63a35c; + font-weight: bold; +} + +.pl-ml /* markup.list */ { + color: #693a17; +} + +.pl-mh /* markup.heading */, +.pl-mh .pl-en /* markup.heading entity.name */, +.pl-ms /* meta.separator */ { + color: #1d3e81; + font-weight: bold; +} + +.pl-mq /* markup.quote */ { + color: #008080; +} + +.pl-mi /* markup.italic */ { + color: #333; + font-style: italic; +} + +.pl-mb /* markup.bold */ { + color: #333; + font-weight: bold; +} + +.pl-md /* markup.deleted, meta.diff.header.from-file */ { + background-color: #ffecec; + color: #bd2c00; +} + +.pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { + background-color: #eaffea; + color: #55a532; +} + +.pl-mdr /* meta.diff.range */ { + color: #795da3; + font-weight: bold; +} + +.pl-mo /* meta.output */ { + color: #1d3e81; +} + diff --git a/stylesheets/print.css b/stylesheets/print.css new file mode 100644 index 0000000..7da6db0 --- /dev/null +++ b/stylesheets/print.css @@ -0,0 +1,228 @@ +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + padding: 0; + margin: 0; + font: inherit; + font-size: 100%; + vertical-align: baseline; + border: 0; +} +/* HTML5 display-role reset for older browsers */ +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-spacing: 0; + border-collapse: collapse; +} +body { + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 13px; + line-height: 1.5; + color: #000; +} + +a { + font-weight: bold; + color: #d5000d; +} + +header { + padding-top: 35px; + padding-bottom: 10px; +} + +header h1 { + font-size: 48px; + font-weight: bold; + line-height: 1.2; + color: #303030; + letter-spacing: -1px; +} + +header h2 { + font-size: 24px; + font-weight: normal; + line-height: 1.3; + color: #aaa; + letter-spacing: -1px; +} +#downloads { + display: none; +} +#main_content { + padding-top: 20px; +} + +code, pre { + margin-bottom: 30px; + font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal; + font-size: 12px; + color: #222; +} + +code { + padding: 0 3px; +} + +pre { + padding: 20px; + overflow: auto; + border: solid 1px #ddd; +} +pre code { + padding: 0; +} + +ul, ol, dl { + margin-bottom: 20px; +} + + +/* COMMON STYLES */ + +table { + width: 100%; + border: 1px solid #ebebeb; +} + +th { + font-weight: 500; +} + +td { + font-weight: 300; + text-align: center; + border: 1px solid #ebebeb; +} + +form { + padding: 20px; + background: #f2f2f2; + +} + + +/* GENERAL ELEMENT TYPE STYLES */ + +h1 { + font-size: 2.8em; +} + +h2 { + margin-bottom: 8px; + font-size: 22px; + font-weight: bold; + color: #303030; +} + +h3 { + margin-bottom: 8px; + font-size: 18px; + font-weight: bold; + color: #d5000d; +} + +h4 { + font-size: 16px; + font-weight: bold; + color: #303030; +} + +h5 { + font-size: 1em; + color: #303030; +} + +h6 { + font-size: .8em; + color: #303030; +} + +p { + margin-bottom: 20px; + font-weight: 300; +} + +a { + text-decoration: none; +} + +p a { + font-weight: 400; +} + +blockquote { + padding: 0 0 0 30px; + margin-bottom: 20px; + font-size: 1.6em; + border-left: 10px solid #e9e9e9; +} + +ul li { + padding-left: 20px; + list-style-position: inside; + list-style: disc; +} + +ol li { + padding-left: 3px; + list-style-position: inside; + list-style: decimal; +} + +dl dd { + font-style: italic; + font-weight: 100; +} + +footer { + padding-top: 20px; + padding-bottom: 30px; + margin-top: 40px; + font-size: 13px; + color: #aaa; +} + +footer a { + color: #666; +} + +/* MISC */ +.clearfix:after { + display: block; + height: 0; + clear: both; + visibility: hidden; + content: '.'; +} + +.clearfix {display: inline-block;} +* html .clearfix {height: 1%;} +.clearfix {display: block;} diff --git a/stylesheets/stylesheet.css b/stylesheets/stylesheet.css new file mode 100644 index 0000000..b75650d --- /dev/null +++ b/stylesheets/stylesheet.css @@ -0,0 +1,881 @@ +/*! normalize.css v3.0.2 | MIT License | git.io/normalize */ + +/** + * 1. Set default font family to sans-serif. + * 2. Prevent iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-family: sans-serif; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + -ms-text-size-adjust: 100%; /* 2 */ +} + +/** + * Remove default margin. + */ + +body { + margin: 0; +} + +/* HTML5 display definitions + ========================================================================== */ + +/** + * Correct `block` display not defined for any HTML5 element in IE 8/9. + * Correct `block` display not defined for `details` or `summary` in IE 10/11 + * and Firefox. + * Correct `block` display not defined for `main` in IE 11. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +main, +menu, +nav, +section, +summary { + display: block; +} + +/** + * 1. Correct `inline-block` display not defined in IE 8/9. + * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + */ + +audio, +canvas, +progress, +video { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Prevent modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Address `[hidden]` styling not present in IE 8/9/10. + * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. + */ + +[hidden], +template { + display: none; +} + +/* Links + ========================================================================== */ + +/** + * Remove the gray background color from active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * Improve readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Address styling not present in IE 8/9/10/11, Safari, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/** + * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +/** + * Address styling not present in Safari and Chrome. + */ + +dfn { + font-style: italic; +} + +/** + * Address variable `h1` font-size and margin within `section` and `article` + * contexts in Firefox 4+, Safari, and Chrome. + */ + +h1 { + margin: 0.67em 0; + font-size: 2em; +} + +/** + * Address styling not present in IE 8/9. + */ + +mark { + color: #000; + background: #ff0; +} + +/** + * Address inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + position: relative; + font-size: 75%; + line-height: 0; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove border when inside `a` element in IE 8/9/10. + */ + +img { + border: 0; +} + +/** + * Correct overflow not hidden in IE 9/10/11. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Grouping content + ========================================================================== */ + +/** + * Address margin not present in IE 8/9 and Safari. + */ + +figure { + margin: 1em 40px; +} + +/** + * Address differences between Firefox and other browsers. + */ + +hr { + height: 0; + -moz-box-sizing: content-box; + box-sizing: content-box; +} + +/** + * Contain overflow in all browsers. + */ + +pre { + overflow: auto; +} + +/** + * Address odd `em`-unit font size rendering in all browsers. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, monospace; + font-size: 1em; +} + +/* Forms + ========================================================================== */ + +/** + * Known limitation: by default, Chrome and Safari on OS X allow very limited + * styling of `select`, unless a `border` property is set. + */ + +/** + * 1. Correct color not being inherited. + * Known issue: affects color of disabled elements. + * 2. Correct font properties not being inherited. + * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. + */ + +button, +input, +optgroup, +select, +textarea { + margin: 0; /* 3 */ + font: inherit; /* 2 */ + color: inherit; /* 1 */ +} + +/** + * Address `overflow` set to `hidden` in IE 8/9/10/11. + */ + +button { + overflow: visible; +} + +/** + * Address inconsistent `text-transform` inheritance for `button` and `select`. + * All other form control elements do not inherit `text-transform` values. + * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. + * Correct `select` style inheritance in Firefox. + */ + +button, +select { + text-transform: none; +} + +/** + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Correct inability to style clickable `input` types in iOS. + * 3. Improve usability and consistency of cursor style between image-type + * `input` and others. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ +} + +/** + * Re-set default cursor for disabled elements. + */ + +button[disabled], +html input[disabled] { + cursor: default; +} + +/** + * Remove inner padding and border in Firefox 4+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + padding: 0; + border: 0; +} + +/** + * Address Firefox 4+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +input { + line-height: normal; +} + +/** + * It's recommended that you don't attempt to style these elements. + * Firefox's implementation doesn't respect box-sizing, padding, or width. + * + * 1. Address box sizing set to `content-box` in IE 8/9/10. + * 2. Remove excess padding in IE 8/9/10. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Fix the cursor style for Chrome's increment/decrement buttons. For certain + * `font-size` values of the `input`, it causes the cursor style of the + * decrement button to change from `default` to `text`. + */ + +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Address `appearance` set to `searchfield` in Safari and Chrome. + * 2. Address `box-sizing` set to `border-box` in Safari and Chrome + * (include `-moz` to future-proof). + */ + +input[type="search"] { + -webkit-box-sizing: content-box; /* 2 */ + -moz-box-sizing: content-box; + box-sizing: content-box; + -webkit-appearance: textfield; /* 1 */ +} + +/** + * Remove inner padding and search cancel button in Safari and Chrome on OS X. + * Safari (but not Chrome) clips the cancel button when the search input has + * padding (and `textfield` appearance). + */ + +input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * Define consistent border, margin, and padding. + */ + +fieldset { + padding: 0.35em 0.625em 0.75em; + margin: 0 2px; + border: 1px solid #c0c0c0; +} + +/** + * 1. Correct `color` not being inherited in IE 8/9/10/11. + * 2. Remove padding so people aren't caught out if they zero out fieldsets. + */ + +legend { + padding: 0; /* 2 */ + border: 0; /* 1 */ +} + +/** + * Remove default vertical scrollbar in IE 8/9/10/11. + */ + +textarea { + overflow: auto; +} + +/** + * Don't inherit the `font-weight` (applied by a rule above). + * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. + */ + +optgroup { + font-weight: bold; +} + +/* Tables + ========================================================================== */ + +/** + * Remove most spacing between table cells. + */ + +table { + border-spacing: 0; + border-collapse: collapse; +} + +td, +th { + padding: 0; +} + +/* LAYOUT STYLES */ +body { + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 15px; + font-weight: 400; + line-height: 1.5; + color: #666; + background: #fafafa url(../images/body-bg.jpg) 0 0 repeat; +} + +p { + margin-top: 0; +} + +a { + color: #2879d0; +} +a:hover { + color: #2268b2; +} + +header { + padding-top: 40px; + padding-bottom: 40px; + font-family: 'Dosis', 'Helvetica Neue', Helvetica, Arial, serif; + background: #2e7bcf url(../images/header-bg.jpg) 0 0 repeat-x; + border-bottom: solid 1px #275da1; +} + +header h1 { + width: 540px; + margin-top: 0; + margin-bottom: 0.2em; + font-size: 72px; + font-weight: normal; + line-height: 1; + color: #fff; + letter-spacing: -1px; +} + +header h2 { + width: 540px; + margin-top: 0; + margin-bottom: 0; + font-size: 26px; + font-weight: normal; + line-height: 1.3; + color: #9ddcff; + letter-spacing: 0; +} + +.inner { + position: relative; + width: 940px; + margin: 0 auto; +} + +#content-wrapper { + padding-top: 30px; + border-top: solid 1px #fff; +} + +#main-content { + float: left; + width: 690px; +} + +#main-content img { + max-width: 100%; +} + +aside#sidebar { + float: right; + width: 200px; + min-height: 504px; + padding-left: 20px; + font-size: 12px; + line-height: 1.3; + background: transparent url(../images/sidebar-bg.jpg) 0 0 no-repeat; +} + +aside#sidebar p.repo-owner, +aside#sidebar p.repo-owner a { + font-weight: bold; +} + +#downloads { + margin-bottom: 40px; +} + +a.button { + width: 134px; + height: 58px; + padding-top: 22px; + padding-left: 68px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 23px; + line-height: 1.2; + color: #fff; +} +a.button small { + display: block; + font-size: 11px; +} +header a.button { + position: absolute; + top: 0; + right: 0; + background: transparent url(../images/github-button.png) 0 0 no-repeat; +} +aside a.button { + display: block; + width: 138px; + padding-left: 64px; + margin-bottom: 20px; + font-size: 21px; + background: transparent url(../images/download-button.png) 0 0 no-repeat; +} + +code, pre { + margin-bottom: 30px; + font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace; + font-size: 13px; + color: #222; +} + +code { + padding: 0 3px; + background-color: #f2f8fc; + border: solid 1px #dbe7f3; +} + +pre { + padding: 20px; + overflow: auto; + text-shadow: none; + background: #fff; + border: solid 1px #f2f2f2; +} +pre code { + padding: 0; + color: #2879d0; + background-color: #fff; + border: none; +} + +ul, ol, dl { + margin-bottom: 20px; +} + + +/* COMMON STYLES */ + +hr { + height: 0; + margin-top: 1em; + margin-bottom: 1em; + border: 0; + border-top: solid 1px #ddd; +} + +table { + width: 100%; + border: 1px solid #ebebeb; +} + +th { + font-weight: 500; +} + +td { + font-weight: 300; + text-align: center; + border: 1px solid #ebebeb; +} + +form { + padding: 20px; + background: #f2f2f2; + +} + + +/* GENERAL ELEMENT TYPE STYLES */ + +#main-content h1 { + margin-top: 0; + margin-bottom: 0; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 2.8em; + font-weight: normal; + color: #474747; + text-indent: 6px; + letter-spacing: -1px; +} + +#main-content h1:before { + padding-right: 0.3em; + margin-left: -0.9em; + color: #9ddcff; + content: "/"; +} + +#main-content h2 { + margin-bottom: 8px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 22px; + font-weight: bold; + color: #474747; + text-indent: 4px; +} +#main-content h2:before { + padding-right: 0.3em; + margin-left: -1.5em; + content: "//"; + color: #9ddcff; +} + +#main-content h3 { + margin-top: 24px; + margin-bottom: 8px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 18px; + font-weight: bold; + color: #474747; + text-indent: 3px; +} + +#main-content h3:before { + padding-right: 0.3em; + margin-left: -2em; + content: "///"; + color: #9ddcff; +} + +#main-content h4 { + margin-bottom: 8px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 15px; + font-weight: bold; + color: #474747; + text-indent: 3px; +} + +h4:before { + padding-right: 0.3em; + margin-left: -2.8em; + content: "////"; + color: #9ddcff; +} + +#main-content h5 { + margin-bottom: 8px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: 14px; + color: #474747; + text-indent: 3px; +} +h5:before { + padding-right: 0.3em; + margin-left: -3.2em; + content: "/////"; + color: #9ddcff; +} + +#main-content h6 { + margin-bottom: 8px; + font-family: 'Helvetica Neue', Helvetica, Arial, serif; + font-size: .8em; + color: #474747; + text-indent: 3px; +} +h6:before { + padding-right: 0.3em; + margin-left: -3.7em; + content: "//////"; + color: #9ddcff; +} + +p { + margin-bottom: 20px; +} + +a { + text-decoration: none; +} + +p a { + font-weight: 400; +} + +blockquote { + padding: 0 0 0 30px; + margin-bottom: 20px; + font-size: 1.6em; + border-left: 10px solid #e9e9e9; +} + +ul { + list-style-position: inside; + list-style: disc; + padding-left: 20px; +} + +ol { + list-style-position: inside; + list-style: decimal; + padding-left: 3px; +} + +dl dd { + font-style: italic; + font-weight: 100; +} + +footer { + padding-top: 20px; + padding-bottom: 30px; + margin-top: 40px; + font-size: 13px; + color: #aaa; + background: transparent url('../images/hr.png') 0 0 no-repeat; +} + +footer a { + color: #666; +} +footer a:hover { + color: #444; +} + +/* MISC */ +.clearfix:after { + display: block; + height: 0; + clear: both; + visibility: hidden; + content: '.'; +} + +.clearfix {display: inline-block;} +* html .clearfix {height: 1%;} +.clearfix {display: block;} + +/* #Media Queries +================================================== */ + +/* Smaller than standard 960 (devices and browsers) */ +@media only screen and (max-width: 959px) { } + +/* Tablet Portrait size to standard 960 (devices and browsers) */ +@media only screen and (min-width: 768px) and (max-width: 959px) { + .inner { + width: 740px; + } + header h1, header h2 { + width: 340px; + } + header h1 { + font-size: 60px; + } + header h2 { + font-size: 30px; + } + #main-content { + width: 490px; + } + #main-content h1:before, + #main-content h2:before, + #main-content h3:before, + #main-content h4:before, + #main-content h5:before, + #main-content h6:before { + padding-right: 0; + margin-left: 0; + content: none; + } +} + +/* All Mobile Sizes (devices and browser) */ +@media only screen and (max-width: 767px) { + .inner { + width: 93%; + } + header { + padding: 20px 0; + } + header .inner { + position: relative; + } + header h1, header h2 { + width: 100%; + } + header h1 { + font-size: 48px; + } + header h2 { + font-size: 24px; + } + header a.button { + position: relative; + display: inline-block; + width: auto; + height: auto; + padding: 5px 10px; + margin-top: 15px; + font-size: 13px; + line-height: 1; + color: #2879d0; + text-align: center; + background-color: #9ddcff; + background-image: none; + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + } + header a.button small { + display: inline; + font-size: 13px; + } + #main-content, + aside#sidebar { + float: none; + width: 100% ! important; + } + aside#sidebar { + min-height: 0; + padding: 20px 0; + margin-top: 20px; + background-image: none; + border-top: solid 1px #ddd; + } + aside#sidebar a.button { + display: none; + } + #main-content h1:before, + #main-content h2:before, + #main-content h3:before, + #main-content h4:before, + #main-content h5:before, + #main-content h6:before { + padding-right: 0; + margin-left: 0; + content: none; + } +} + +/* Mobile Landscape Size to Tablet Portrait (devices and browsers) */ +@media only screen and (min-width: 480px) and (max-width: 767px) { } + +/* Mobile Portrait Size to Mobile Landscape Size (devices and browsers) */ +@media only screen and (max-width: 479px) { } + diff --git a/thread/Input b/thread/Input deleted file mode 100644 index 1cc48de..0000000 --- a/thread/Input +++ /dev/null @@ -1,4 +0,0 @@ -process-a 100 500 2 a -process-b 200 300 1 b -process-c 300 100 1 c -process-d 700 100 4 d \ No newline at end of file diff --git a/thread/priorityBased/nonpremitive/CPU.java b/thread/priorityBased/nonpremitive/CPU.java deleted file mode 100644 index ab3d00e..0000000 --- a/thread/priorityBased/nonpremitive/CPU.java +++ /dev/null @@ -1,84 +0,0 @@ -/************************************************************************************************ -* Developer: Minhas Kamal(BSSE-0509, IIT, DU) * -* Date: Sep-2014 * -*************************************************************************************************/ - -package thread.priorityBased.nonpremitive; - -import java.util.LinkedList; -import java.util.Queue; - -import thread.utilClasses.Process; -import thread.utilClasses.Result; - -public class CPU { - private final int CPU_CYCLE_TIME = 100; - - public int time; - public Queue waitingQueue = new LinkedList(); - public Queue result = new LinkedList(); - - - public Queue runProcess(Queue processes){ - - while(!processes.isEmpty() || !waitingQueue.isEmpty()){ - - while(!processes.isEmpty() && processes.element().arrivalTime<=time){ - waitingQueue.add(processes.peek()); - processes.remove(); - } - - - //run the program - if(!waitingQueue.isEmpty()){ - order(waitingQueue); - - waitingQueue.element().cpuTime -= CPU_CYCLE_TIME; - waitingQueue.element().arrivalTime += CPU_CYCLE_TIME; - - - if(waitingQueue.element().cpuTime<=0){ - int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME; - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime)); - - waitingQueue.remove(); - }else{ - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol)); - } - - }else{ //idle time, no process is waiting - result.add(new Result()); - } - - time += CPU_CYCLE_TIME; - } - - - return result; - } - - private void order(Queue waitingQueue){ - int waitingQueueLength = waitingQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processQueue = new LinkedList(); - public Queue results = new LinkedList(); - - public void priorityBasedNonpremitiveImpl(String fileName){ - int noOfProcess; - processQueue = takeInput(fileName); - noOfProcess = processQueue.size(); - - order(processQueue); - - results = new CPU().runProcess(processQueue); - - float totalWaitingTime = 0; - Queue symbol = new LinkedList(); - - for(Result result: results){ - //System.out.println(result.symbol + " -> " + result.waitingTime); - - symbol.add(result.symbol); - - if(result.waitingTime>0){ - totalWaitingTime += result.waitingTime; - } - } - - //System.out.println("\n\n\nAverage waiting time: " + totalWaitingTime/noOfProcess); - - new Graph(symbol, totalWaitingTime/noOfProcess).setVisible(true); - } - - private Queue takeInput(String fileName){ - Queue processQueue = new LinkedList(); - - try { - String string = new String(); // for temporary data store - BufferedReader mainBR = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName))); - - String jobName; - int arrivalTime; - int cpuTime; - int priority; - char symbol; - - int startIndex=0; - int stopIndex=-1; - - string = mainBR.readLine(); - while (string != null) { // reading step by step - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - jobName = string.substring(startIndex, stopIndex); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - arrivalTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - cpuTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - priority = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf('\n', startIndex); - symbol = string.charAt(startIndex); - - processQueue.add(new Process(jobName, arrivalTime, cpuTime, priority, symbol)); - - string = mainBR.readLine(); - } - - mainBR.close(); // closing the file - - }catch (Exception e) { - e.printStackTrace(); - } - - /*///test - processQueue.add(new Process("process-1", 100, 400, 2, '1')); - processQueue.add(new Process("process-2", 200, 600, 1, '2')); - processQueue.add(new Process("process-3", 100, 100, 1, '3')); - processQueue.add(new Process("process-4", 300, 300, 3, '4')); - /**/ - return processQueue; - } - - private void order(Queue processQueue){ - int waitingQueueLength = processQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].arrivalTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i waitingQueue = new LinkedList(); - public Queue result = new LinkedList(); - - - public Queue runProcess(Queue processes){ - - while(!processes.isEmpty() || !waitingQueue.isEmpty()){ - - //process starts - while(!processes.isEmpty() && processes.element().arrivalTime<=time){ - waitingQueue.add(processes.peek()); - processes.remove(); - order(waitingQueue); - } - - - //run the program - if(!waitingQueue.isEmpty()){ - waitingQueue.element().cpuTime -= CPU_CYCLE_TIME; - waitingQueue.element().arrivalTime += CPU_CYCLE_TIME; - - - if(waitingQueue.element().cpuTime<=0){ //process ends - int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME; - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime)); - - waitingQueue.remove(); - }else{ - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol)); - } - }else{ //idle time, no process is waiting - result.add(new Result()); - } - - time += CPU_CYCLE_TIME; - } - - - return result; - } - - private void order(Queue waitingQueue){ - int waitingQueueLength = waitingQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processQueue = new LinkedList(); - public Queue results = new LinkedList(); - - /** - * - * @param fileName - */ - public void priorityBasedPremitiveImpl(String fileName){ - int noOfProcess; - processQueue = takeInput(fileName); - noOfProcess = processQueue.size(); - - order(processQueue); - - results = new CPU().runProcess(processQueue); - - float totalWaitingTime = 0; - Queue symbol = new LinkedList(); - - for(Result result: results){ - //System.out.println(result.symbol + " -> " + result.waitingTime); - - symbol.add(result.symbol); - - if(result.waitingTime>0){ - totalWaitingTime += result.waitingTime; - } - } - - //System.out.println("\n\n\nAverage waiting time: " + totalWaitingTime/noOfProcess); - - new Graph(symbol, totalWaitingTime/noOfProcess).setVisible(true); - } - - private Queue takeInput(String fileName){ - Queue processQueue = new LinkedList(); - - try { - String string = new String(); // for temporary data store - BufferedReader mainBR = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName))); - - String jobName; - int arrivalTime; - int cpuTime; - int priority; - char symbol; - - int startIndex=0; - int stopIndex=-1; - - string = mainBR.readLine(); - while (string != null) { // reading step by step - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - jobName = string.substring(startIndex, stopIndex); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - arrivalTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - cpuTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - priority = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf('\n', startIndex); - symbol = string.charAt(startIndex); - - processQueue.add(new Process(jobName, arrivalTime, cpuTime, priority, symbol)); - - string = mainBR.readLine(); - } - - mainBR.close(); // closing the file - - }catch (Exception e) { - e.printStackTrace(); - } - - /*///test - processQueue.add(new Process("process-1", 100, 400, 2, '1')); - processQueue.add(new Process("process-2", 200, 600, 1, '2')); - processQueue.add(new Process("process-3", 100, 100, 1, '3')); - processQueue.add(new Process("process-4", 300, 300, 3, '4')); - /**/ - return processQueue; - } - - private void order(Queue processQueue){ - int waitingQueueLength = processQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].arrivalTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i waitingQueue = new LinkedList(); - public Queue result = new LinkedList(); - - - public Queue runProcess(Queue processes){ - - while(!processes.isEmpty() || !waitingQueue.isEmpty()){ - - //process starts - while(!processes.isEmpty() && processes.element().arrivalTime<=time){ - waitingQueue.add(processes.peek()); - processes.remove(); - } - - - //run the program - if(!waitingQueue.isEmpty()){ //when there is process to be processed - - order(waitingQueue); - - waitingQueue.element().cpuTime -= CPU_CYCLE_TIME; - waitingQueue.element().arrivalTime += CPU_CYCLE_TIME; - - if(waitingQueue.element().cpuTime<=0){ //process ends - int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME; - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime)); - - waitingQueue.remove(); - }else{ - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol)); - } - - }else{ //idle time, no process is waiting - result.add(new Result()); - } - - time += CPU_CYCLE_TIME; - } - - - return result; - } - - private void order(Queue waitingQueue){ - int waitingQueueLength = waitingQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].cpuTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i processQueue = new LinkedList(); - public Queue results = new LinkedList(); - - public void shortestJobFirstNonpremitiveImpl(String fileName){ - int noOfProcess; - processQueue = takeInput(fileName); - noOfProcess = processQueue.size(); - - order(processQueue); - - results = new CPU().runProcess(processQueue); - - float totalWaitingTime = 0; - Queue symbol = new LinkedList(); - - for(Result result: results){ - //System.out.println(result.symbol + " -> " + result.waitingTime); - - symbol.add(result.symbol); - - if(result.waitingTime>0){ - totalWaitingTime += result.waitingTime; - } - } - - //System.out.println("\n\n\nAverage waiting time: " + totalWaitingTime/noOfProcess); - - new Graph(symbol, totalWaitingTime/noOfProcess).setVisible(true); - } - - private Queue takeInput(String fileName){ - Queue processQueue = new LinkedList(); - - try { - String string = new String(); // for temporary data store - BufferedReader mainBR = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName))); - - String jobName; - int arrivalTime; - int cpuTime; - int priority; - char symbol; - - int startIndex=0; - int stopIndex=-1; - - string = mainBR.readLine(); - while (string != null) { // reading step by step - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - jobName = string.substring(startIndex, stopIndex); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - arrivalTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - cpuTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - priority = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf('\n', startIndex); - symbol = string.charAt(startIndex); - - processQueue.add(new Process(jobName, arrivalTime, cpuTime, priority, symbol)); - - string = mainBR.readLine(); - } - - mainBR.close(); // closing the file - - }catch (Exception e) { - e.printStackTrace(); - } - - /*///test - processQueue.add(new Process("process-1", 100, 400, 2, '1')); - processQueue.add(new Process("process-2", 200, 600, 1, '2')); - processQueue.add(new Process("process-3", 100, 100, 1, '3')); - processQueue.add(new Process("process-4", 300, 300, 3, '4')); - /**/ - return processQueue; - } - - private void order(Queue processQueue){ - int waitingQueueLength = processQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].arrivalTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i waitingQueue = new LinkedList(); - public Queue result = new LinkedList(); - - - public Queue runProcess(Queue processes){ - - while(!processes.isEmpty() || !waitingQueue.isEmpty()){ - //process starts - while(!processes.isEmpty() && processes.element().arrivalTime<=time){ - waitingQueue.add(processes.peek()); - processes.remove(); - } - - //run the program - if(!waitingQueue.isEmpty()){ - order(waitingQueue); - - waitingQueue.element().cpuTime -= CPU_CYCLE_TIME; - waitingQueue.element().arrivalTime += CPU_CYCLE_TIME; - - if(waitingQueue.element().cpuTime<=0){ //process ends - int waitingTime = time - waitingQueue.element().arrivalTime + CPU_CYCLE_TIME; - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol, waitingTime)); - - waitingQueue.remove(); - }else{ - result.add(new Result(waitingQueue.element().jobName, waitingQueue.element().symbol)); - } - }else{ //idle time, no process is waiting - result.add(new Result()); - } - - time += CPU_CYCLE_TIME; - } - - - return result; - } - - private void order(Queue waitingQueue){ - int waitingQueueLength = waitingQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].cpuTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i processQueue = new LinkedList(); - public Queue results = new LinkedList(); - - public void shortestJobFirstPremitiveImpl(String fileName){ - int noOfProcess; - processQueue = takeInput(fileName); - noOfProcess = processQueue.size(); - - order(processQueue); - - results = new CPU().runProcess(processQueue); - - float totalWaitingTime = 0; - Queue symbol = new LinkedList(); - - for(Result result: results){ - //System.out.println(result.symbol + " -> " + result.waitingTime); - - symbol.add(result.symbol); - - if(result.waitingTime>0){ - totalWaitingTime += result.waitingTime; - } - } - - //System.out.println("\n\n\nAverage waiting time: " + totalWaitingTime/noOfProcess); - - new Graph(symbol, totalWaitingTime/noOfProcess).setVisible(true); - } - - private Queue takeInput(String fileName){ - Queue processQueue = new LinkedList(); - - try { - String string = new String(); // for temporary data store - BufferedReader mainBR = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(fileName))); - - String jobName; - int arrivalTime; - int cpuTime; - int priority; - char symbol; - - int startIndex=0; - int stopIndex=-1; - - string = mainBR.readLine(); - while (string != null) { // reading step by step - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - jobName = string.substring(startIndex, stopIndex); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - arrivalTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - cpuTime = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf(' ', startIndex); - priority = Integer.parseInt(string.substring(startIndex, stopIndex)); - - startIndex=stopIndex+1; - stopIndex=string.indexOf('\n', startIndex); - symbol = string.charAt(startIndex); - - processQueue.add(new Process(jobName, arrivalTime, cpuTime, priority, symbol)); - - string = mainBR.readLine(); - } - - mainBR.close(); // closing the file - - }catch (Exception e) { - e.printStackTrace(); - } - - /*///test - processQueue.add(new Process("process-1", 100, 400, 2, '1')); - processQueue.add(new Process("process-2", 200, 600, 1, '2')); - processQueue.add(new Process("process-3", 100, 100, 1, '3')); - processQueue.add(new Process("process-4", 300, 300, 3, '4')); - /**/ - return processQueue; - } - - private void order(Queue processQueue){ - int waitingQueueLength = processQueue.size(); - Process[] processes = new Process[waitingQueueLength]; - - for(int i=0; i processes[j].arrivalTime){ - tempProcess = processes[i]; - processes[i] = processes[j]; - processes[j] = tempProcess; - } - } - } - - for(int i=0; i symbols, float f) { - parts = symbols.size(); - - initialComponent(symbols, f); - } - - - /** - * Method for Initializing all the GUI variables, placing them all to specific space on the frame and adding action - * listener to them. Also specifies criteria of the main frame. - */ - private void initialComponent(Queue symbols, float f) { - //** - // Initialization #*******I*******# - //** - jPanelMain = new JPanel(); - jPanelGraph = new JPanel[parts]; - jLabel = new JLabel(); - //other variables - Queue uniqueSymbols = new LinkedList(); - // End of Initialization #_______I_______# - - //** - // Setting Bounds and Attributes of the Elements #*******S*******# - //** - jPanelMain.setBounds(0, 0, LENGTH+40, 250); - jPanelMain.setBackground(new Color(-1)); - jPanelMain.setLayout(null); - - int partLength = LENGTH/parts; - for(int i=0; i symbol = new LinkedList(); - symbol.add('a');symbol.add('a');symbol.add('b');symbol.add('c'); - symbol.add('a');symbol.add('c');symbol.add('c');symbol.add('d'); - symbol.add('a');symbol.add('b');symbol.add('c');symbol.add('e'); - symbol.add('f');symbol.add('f');symbol.add('f');symbol.add('c'); - symbol.add('a');symbol.add('g');symbol.add('g');symbol.add('d'); - symbol.add('h');symbol.add('h');symbol.add('h');symbol.add('e'); - symbol.add('a');symbol.add('a');symbol.add('c');symbol.add('c'); - symbol.add('i');symbol.add('j');symbol.add('k');symbol.add('i'); - symbol.add('j');symbol.add('j');symbol.add('j');symbol.add('k'); - - Graph gui = new Graph(symbol, 100); - gui.setVisible(true); - } - - //** - // Auxiliary Methods #********AM*******# - //** - - private int getPosition(char symbol, Queue uniqueSymbols){ - int position = -1; - - int p = 0; - for(Character uniqueSymbol: uniqueSymbols){ - if(symbol==uniqueSymbol){ - position=p; - break; - } - p++; - } - - return position; - } - - private Color getColor(int i){ - i *= 150; - - int r = i%256; - int g = i%200+i%56; - int b = i%100+i%156; - - Color color = new Color(r, g, b); - return color; - } - // End of Auxiliary Methods #________AM_______# -} diff --git a/thread/utilClasses/Process.java b/thread/utilClasses/Process.java deleted file mode 100644 index 2488095..0000000 --- a/thread/utilClasses/Process.java +++ /dev/null @@ -1,39 +0,0 @@ -/************************************************************************************************ -* Developer: Minhas Kamal(BSSE-0509, IIT, DU) * -* Date: Sep-2014 * -*************************************************************************************************/ - -package thread.utilClasses; - -public class Process { - public String jobName; - public int arrivalTime; - public int cpuTime; - public int priority; - public char symbol; - - public Process(){ - this.jobName = ""; - this.arrivalTime = 0; - this.cpuTime = 0; - this.priority = 1; - this.symbol = '0'; - } - - public Process(String jobName, int arrivalTime, int cpuTime, char symbol){ - this.jobName = jobName; - this.arrivalTime = arrivalTime; - this.cpuTime = cpuTime; - this.priority = 1; - this.symbol = symbol; - } - - public Process(String jobName, int arrivalTime, int cpuTime, int priority, char symbol){ - this.jobName = jobName; - this.arrivalTime = arrivalTime; - this.cpuTime = cpuTime; - this.priority = priority; - this.symbol = symbol; - } - -} diff --git a/thread/utilClasses/Result.java b/thread/utilClasses/Result.java deleted file mode 100644 index ae0ddde..0000000 --- a/thread/utilClasses/Result.java +++ /dev/null @@ -1,30 +0,0 @@ -/************************************************************************************************ -* Developer: Minhas Kamal(BSSE-0509, IIT, DU) * -* Date: Sep-2014 * -*************************************************************************************************/ - -package thread.utilClasses; - -public class Result { - public String jobName; - public char symbol; - public float waitingTime; - - public Result() { - this.jobName = "EMPTY"; - this.symbol = ' '; - waitingTime = -1; - } - - public Result(String jobName, char symbol){ - this.jobName = jobName; - this.symbol = symbol; - waitingTime = -1; - } - - public Result(String jobName, char symbol, float waitingTime){ - this.jobName = jobName; - this.symbol = symbol; - this.waitingTime = waitingTime; - } -}