Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 49 additions & 9 deletions Exercise_1.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
class Stack {
// Time Complexity : O(1) for push(), pop(), peek(), and isEmpty()
// Space Complexity : O(n) for storing n elements in the stack
// Did this code successfully run on Leetcode :
// Any problem you faced while coding this : None


// Your code here along with comments explaining your approach

class Stack {
//Please read sample.java file before starting.
//Kindly include Time and Space complexity at top of each file
static final int MAX = 1000;
int top;
int a[] = new int[MAX]; // Maximum size of Stack

boolean isEmpty()
{
//Write your code here
{
// return true if stack is empty
if(top == -1){
return true;
} else {
return false;
}
}

Stack()
{
//Initialize your constructor
}

//Initialize your constructor
top = -1;
}

boolean push(int x)
{
{
// insert an element on top of stack
//Check for stack Overflow
//Write your code here
if (top == MAX-1) {
System.out.println("Stack Overflow");
return false;
} else {
top++;
a[top] = x;
return true;
}
}

int pop()
{
{
// pop the topmost element of stack
//If empty return 0 and print " Stack Underflow"
//Write your code here
if (top == -1) {
System.out.println("Stack Underflow");
return 0;
} else {
int ele = a[top];
top--;
return ele;
}


}

int peek()
{
{
// return the topmost element of stack
//Write your code here
if (top == -1) {
return 0;
} else {
return a[top];
}
}
}

Expand Down
52 changes: 0 additions & 52 deletions Exercise_2.java

This file was deleted.

70 changes: 0 additions & 70 deletions Exercise_3.java

This file was deleted.

88 changes: 88 additions & 0 deletions LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Time Complexity : insert() -> O(1), printList() -> O(n)
// Space Complexity : O(n)
// Did this code successfully run on Leetcode :
// Any problem you faced while coding this : No

// Your code here along with comments explaining your approach

import java.io.*;

// Java program to implement
// a Singly Linked List
public class LinkedList {

Node head;// head of list
Node tail;//tail of list

// Linked list Node.
// This inner class is made static
// so that main() can access it
static class Node {

int data;
Node next;

// Constructor
Node(int d)
{
this.data = d;
//Write your code here
}
}

// Method to insert a new node
public static LinkedList insert(LinkedList list, int data)
{
// Create a new node with given data
Node node = new Node(data);

// If the Linked List is empty,
// then make the new node as head
// Else append the new node at the end and update tail
if (list.head == null) {
list.head = node;
list.tail = node;
return list;
} else {
list.tail.next = node;
list.tail = node;
return list;
}


}

// Method to print the LinkedList.
public static void printList(LinkedList list)
{
// assign head to a temp node
// print data of each node until temp is null
Node temp = list.head;
while (temp!= null) {
System.out.println(temp.data);
temp = temp.next;
}

}

// Driver code
public static void main(String[] args)
{
/* Start with the empty list. */
LinkedList list = new LinkedList();

//
// ******INSERTION******
//

// Insert the values
list = insert(list, 1);
list = insert(list, 2);
list = insert(list, 3);
list = insert(list, 4);
list = insert(list, 5);

// Print the LinkedList
printList(list);
}
}
11 changes: 11 additions & 0 deletions PreCourse-1.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading