Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arranged All Files #Hacktoberfest2022 #77

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c79abcf
Rename ArrayList.java to java/ArrayList.java
Rabhinav2003 Oct 21, 2022
8d122d6
Rename BinarySearch.java to java/BinarySearch.java
Rabhinav2003 Oct 21, 2022
37107dd
Rename Bogo_sort.java to java/Bogo_sort.java
Rabhinav2003 Oct 21, 2022
3c67cc9
Rename Calculator.java to java/Calculator.java
Rabhinav2003 Oct 21, 2022
6a12d41
Rename CrudCurrencyConvertor.java to java/CrudCurrencyConvertor.java
Rabhinav2003 Oct 21, 2022
0dca8d5
Rename GuessTheNumberGame.java to java/GuessTheNumberGame.java
Rabhinav2003 Oct 21, 2022
f1f143a
Rename Heap_Sort.java to java/Heap_Sort.java
Rabhinav2003 Oct 21, 2022
5f1ca28
Rename Linked_list.java to java/Linked_list.java
Rabhinav2003 Oct 21, 2022
8c6c025
Rename InsertionSort.java to java/InsertionSort.java
Rabhinav2003 Oct 21, 2022
9b84269
Rename warshall.java to java/warshall.java
Rabhinav2003 Oct 21, 2022
01ebf7a
Rename secondlargest.java to java/secondlargest.java
Rabhinav2003 Oct 21, 2022
7bb53ed
Rename reverseLinkedList.java to java/reverseLinkedList.java
Rabhinav2003 Oct 21, 2022
7b4a0c8
Rename QuickSort.java to java/QuickSort.java
Rabhinav2003 Oct 21, 2022
8557ef9
Rename LongestPath.java to java/LongestPath.java
Rabhinav2003 Oct 21, 2022
7292f7f
Rename SelectionSort.java to java/SelectionSort.java
Rabhinav2003 Oct 21, 2022
ffe7ed2
Rename fibonacci_series.java to java/fibonacci_series.java
Rabhinav2003 Oct 21, 2022
0a2b508
Rename palindro.java to java/palindro.java
Rabhinav2003 Oct 21, 2022
5f4f51e
Rename palindrome.java to java/palindrome.java
Rabhinav2003 Oct 21, 2022
880b940
Rename nextGreaterElement_stack.java to java/nextGreaterElement_stack…
Rabhinav2003 Oct 21, 2022
27c55c1
Rename emirp.java to java/emirp.java
Rabhinav2003 Oct 21, 2022
8ceb6d9
Rename bubbleSort.java to java/bubbleSort.java
Rabhinav2003 Oct 21, 2022
298829f
Rename SortHeap.java to java/SortHeap.java
Rabhinav2003 Oct 21, 2022
e3b7bd2
Rename Rock-Paper-scissors game to java/Rock-Paper-scissors game.java
Rabhinav2003 Oct 21, 2022
06467db
Rename StringBuilderQuestions.java to java/StringBuilderQuestions.java
Rabhinav2003 Oct 21, 2022
faafd64
Rename Transpose Matrix.java to java/Transpose Matrix.java
Rabhinav2003 Oct 21, 2022
38ad9d1
Rename DFS.cpp to C++/DFS.cpp
Rabhinav2003 Oct 21, 2022
6293da4
Create tictactoe.cpp
Rabhinav2003 Oct 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DFS.cpp → C++/DFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ int main()
}

return 0;
}
}
125 changes: 125 additions & 0 deletions c++/tictactoe.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//Tic Tac Toe Game in C++

//Importing the inbuild libraries in CPP
#include <iostream>
#include <stdlib.h>
using namespace std;
//Array for the board
char board[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}};
//Variable Declaration
int choice;
int row,column;
char turn = 'X';
bool draw = false;

//Function to show the current status of the gaming board

void display_board(){

//Rander Game Board LAYOUT

cout<<"PLAYER - 1 [X]t PLAYER - 2 [O]nn";
cout<<"tt | | n";
cout<<"tt "<<board[0][0]<<" | "<<board[0][1]<<" | "<<board[0][2]<<" n";
cout<<"tt_____|_____|_____n";
cout<<"tt | | n";
cout<<"tt "<<board[1][0]<<" | "<<board[1][1]<<" | "<<board[1][2]<<" n";
cout<<"tt_____|_____|_____n";
cout<<"tt | | n";
cout<<"tt "<<board[2][0]<<" | "<<board[2][1]<<" | "<<board[2][2]<<" n";
cout<<"tt | | n";
}

//Function to get the player input and update the board

void player_turn(){
if(turn == 'X'){
cout<<"ntPlayer - 1 [X] turn : ";
}
else if(turn == 'O'){
cout<<"ntPlayer - 2 [O] turn : ";
}
//Taking input from user
//updating the board according to choice and reassigning the turn Start

cin>> choice;

//switch case to get which row and column will be update

switch(choice){
case 1: row=0; column=0; break;
case 2: row=0; column=1; break;
case 3: row=0; column=2; break;
case 4: row=1; column=0; break;
case 5: row=1; column=1; break;
case 6: row=1; column=2; break;
case 7: row=2; column=0; break;
case 8: row=2; column=1; break;
case 9: row=2; column=2; break;
default:
cout<<"Invalid Move";
}

if(turn == 'X' && board[row][column] != 'X' && board[row][column] != 'O'){
//updating the position for 'X' symbol if
//it is not already occupied
board[row][column] = 'X';
turn = 'O';
}else if(turn == 'O' && board[row][column] != 'X' && board[row][column] != 'O'){
//updating the position for 'O' symbol if
//it is not already occupied
board[row][column] = 'O';
turn = 'X';
}else {
//if input position already filled
cout<<"Box already filled!n Please choose another!!nn";
player_turn();
}
/* Ends */
display_board();
}

//Function to get the game status e.g. GAME WON, GAME DRAW GAME IN CONTINUE MODE

bool gameover(){
//checking the win for Simple Rows and Simple Column
for(int i=0; i<3; i++)
if(board[i][0] == board[i][1] && board[i][0] == board[i][2] || board[0][i] == board[1][i] && board[0][i] == board[2][i])
return false;

//checking the win for both diagonal

if(board[0][0] == board[1][1] && board[0][0] == board[2][2] || board[0][2] == board[1][1] && board[0][2] == board[2][0])
return false;

//Checking the game is in continue mode or not
for(int i=0; i<3; i++)
for(int j=0; j<3; j++)
if(board[i][j] != 'X' && board[i][j] != 'O')
return true;

//Checking the if game already draw
draw = true;
return false;
}

//Program Main Method

int main()
{
cout<<"tttT I C K -- T A C -- T O E -- G A M Ettt";
cout<<"nttttFOR 2 PLAYERSnttt";
while(gameover()){
display_board();
player_turn();
gameover();
}
if(turn == 'X' && draw == false){
cout<<"nnCongratulations!Player with 'X' has won the game";
}
else if(turn == 'O' && draw == false){
cout<<"nnCongratulations!Player with 'O' has won the game";
}
else
cout<<"nnGAME DRAW!!!nn";
}
File renamed without changes.
2 changes: 1 addition & 1 deletion BinarySearch.java → java/BinarySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public static void main(String args[]){
int last=arr.length-1;
binarySearch(arr,0,last,key);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Linked_list.java → java/Linked_list.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ public static void main(String[] args) {
//Displays the nodes present in the list
sList.display();
}
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion QuickSort.java → java/QuickSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ public static void main(String[] args)
System.out.println("Sorted array: ");
printArray(arr, n);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Transpose Matrix.java → java/Transpose Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public int[][] transpose(int[][] matrix) {

return arr;
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.