├── GUI ├── AppletDemo.java └── gui.java ├── JAVA ├── commandline arguments │ ├── Add.java │ ├── reverse.java │ ├── max.java │ └── prime.java ├── Packages │ └── a.java ├── scanner │ ├── Factorial.java │ ├── Fibonacci.java │ ├── Sum.java │ └── Armstrong.java ├── interface │ ├── InterfaceDemoJava.java │ └── InterfaceDemo.java ├── multithreading │ └── ThreadDemo.java └── matrix │ └── matrix.java ├── DSA ├── LinearSearch.c ├── SelectionSort.c ├── BubbleSort.c ├── MergeSort.c ├── BinarySearch.c ├── stack.c ├── stacks.c ├── COPY_CON_LL.c ├── linkedlist.c ├── deque.c └── L_Limplement.c ├── .gitignore └── LICENSE /GUI/AppletDemo.java: -------------------------------------------------------------------------------- 1 | import java.applet.*; 2 | import java.awt.*; 3 | 4 | public class AppletDemo extends Applet{ 5 | public void paint(Graphics g){ 6 | g.drawString("Hello World", 10, 100); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /JAVA/commandline arguments/Add.java: -------------------------------------------------------------------------------- 1 | class Add{ 2 | public static void main(String args[]){ 3 | int x,y; 4 | x = Integer.parseInt(args[0]); 5 | y = Integer.parseInt(args[1]); 6 | int sum; 7 | sum = x + y; 8 | System.out.println(sum); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /JAVA/Packages/a.java: -------------------------------------------------------------------------------- 1 | package pack1; 2 | public class a 3 | { 4 | public void display() 5 | { 6 | System.out.println("Inside class A"); 7 | } 8 | } 9 | 10 | import pack1.A; 11 | class test 12 | { 13 | public static void main (String args[]) 14 | { 15 | a A = new a(); 16 | A.display(); 17 | } 18 | } -------------------------------------------------------------------------------- /JAVA/commandline arguments/reverse.java: -------------------------------------------------------------------------------- 1 | class reverse{ 2 | public static void main(String args[]){ 3 | int n,rem; 4 | int rev = 0; 5 | n = Integer.parseInt(args[0]); 6 | while(n!=0) 7 | { 8 | rem = n%10; 9 | rev = rev*10 + rem; 10 | n=n/10; 11 | } 12 | System.out.println(rev + “ is the reversed number”); 13 | } 14 | } -------------------------------------------------------------------------------- /DSA/LinearSearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int a[] = {-10, -4, 0, 10, 12, 13, 24, 56, 100}; 6 | int n = sizeof(a) / sizeof(a[0]); 7 | // Search keys 8 | int x = 12; 9 | int i; 10 | for (i = 0; i < n; ++i) 11 | { 12 | if (i[a] == x) 13 | { 14 | printf("%d found at index - %d\n", x, i); 15 | } 16 | } 17 | if (i == n) 18 | printf("%d not found\n", x); 19 | } 20 | -------------------------------------------------------------------------------- /JAVA/scanner/Factorial.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Factorial{ 3 | public static void main(String args[]){ 4 | Scanner scan = new Scanner(System.in); 5 | int n , fact = 1; 6 | System.out.println("Enter the number to find factorial"); 7 | n = scan.nextInt(); 8 | for(int i = 1; i<=n; i++){ 9 | fact = fact*i; 10 | } 11 | System.out.println(fact + " is the required factorial"); 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /JAVA/scanner/Fibonacci.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Fibonacci { 3 | public static void main(String args[]){ 4 | int t1 =0; 5 | int t2 =1; 6 | int nt; 7 | int n; 8 | System.out.println("Enter the number of terms"); 9 | Scanner scan = new Scanner(System.in); 10 | n = scan.nextInt(); 11 | for(int x = 0; xa) 9 | { 10 | max = b; 11 | if(b>c) 12 | { 13 | max=b; 14 | } 15 | else 16 | { 17 | max=c; 18 | } 19 | } 20 | System.out.println("The largest number is "+max); 21 | } 22 | } -------------------------------------------------------------------------------- /JAVA/scanner/Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Sum{ 3 | public static void main(String args[]){ 4 | Scanner scan = new Scanner(System.in); 5 | int i = 0,n,temp; 6 | int a[]; 7 | a = new int[3]; 8 | int sum = 0; 9 | System.out.println("Enter the number "); 10 | n = scan.nextInt(); 11 | temp = n; 12 | while(n!=0) 13 | { 14 | a[i] = n%10; 15 | n=n/10; 16 | i++; 17 | } 18 | for(i = 0; i<3; i++){ 19 | sum = sum + a[i]; 20 | } 21 | System.out.println(sum +" is sum of the given number"); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /DSA/SelectionSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void selectionSort(int a[], int n) 4 | { 5 | for(int i=0;i 2 | 3 | void swap(int *x, int *y) 4 | { 5 | int t = *x; 6 | *x = *y; 7 | *y = t; 8 | } 9 | 10 | void bubbleSort(int a[], int n) 11 | { 12 | for (int i = 0; i < n; ++i) 13 | { 14 | for (int j = 0; j < n - i-1; ++j) 15 | { 16 | if(a[j] > a[j+1]) 17 | { 18 | swap(&a[j], &a[j+1]); 19 | } 20 | } 21 | } 22 | } 23 | 24 | void printArr(int *a, int n) 25 | { 26 | for (int i = 0; i < n; ++i) 27 | { 28 | printf("%d ", a[i]); 29 | } 30 | } 31 | 32 | int main() 33 | { 34 | int a[] = {30, -10, 15, 0, 50, 75}; 35 | int n = sizeof(a) / sizeof(a[0]); 36 | bubbleSort(a, n); 37 | printArr(a, n); 38 | } 39 | -------------------------------------------------------------------------------- /JAVA/commandline arguments/prime.java: -------------------------------------------------------------------------------- 1 | class prime 2 | { 3 | public static void main(String args[]) 4 | { 5 | int i,m=0,flag=0; 6 | int n=Integer.parseInt(args[0]); 7 | m=n/2; 8 | if(n==0||n==1) 9 | { 10 | System.out.println(n+" is not prime number"); 11 | } 12 | else 13 | { 14 | for(i=2;i<=m;i++) 15 | { 16 | if(n%i==0) 17 | { 18 | System.out.println(n+" is not prime number"); 19 | flag=1; 20 | break; 21 | } 22 | } 23 | if(flag==0) 24 | { 25 | System.out.println(n+" is prime number"); 26 | } 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /JAVA/scanner/Armstrong.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Armstrong{ 3 | public static void main(String args[]){ 4 | Scanner scan = new Scanner(System.in); 5 | int i = 0,n,temp; 6 | int a[]; 7 | a = new int[3]; 8 | int sum = 0; 9 | System.out.println("Enter the number "); 10 | n = scan.nextInt(); 11 | temp = n; 12 | while(n!=0) 13 | { 14 | a[i] = n%10; 15 | n=n/10; 16 | i++; 17 | } 18 | for(i = 0; i<3; i++){ 19 | sum = sum + a[i]*a[i]*a[i]; 20 | } 21 | if(sum == temp){ 22 | System.out.println(temp+" is an armstrong number"); 23 | }else{ 24 | System.out.println(temp+" is not an armstrong number"); 25 | } 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /JAVA/interface/InterfaceDemo.java: -------------------------------------------------------------------------------- 1 | 2 | interface Area{ 3 | final static double pi = 3.14; 4 | double compute(double x , double y); 5 | } 6 | class Rectangle implements Area{ 7 | public double compute(double x , double y) 8 | { 9 | return x*y; 10 | } 11 | } 12 | class Circle implements Area{ 13 | public double compute(double x, double y) 14 | { 15 | return pi*x*y; 16 | } 17 | } 18 | class InterfaceDemo{ 19 | public static void main(String Args[]){ 20 | Rectangle r = new Rectangle(); 21 | Circle c = new Circle(); 22 | Area ar; 23 | ar = r; 24 | System.out.println("Area of Rectangle " + ar.compute(10.0,10.0) ); 25 | ar = c; 26 | System.out.println("Area of Circle" + ar.compute(10.0,10.0) ); 27 | } 28 | } -------------------------------------------------------------------------------- /JAVA/multithreading/ThreadDemo.java: -------------------------------------------------------------------------------- 1 | class A extends Thread{ 2 | public void run(){ 3 | for(int i = 0 ; i<=5; i++){ 4 | System.out.println("From thread A = i " + i); 5 | } 6 | System.out.println("Exit from A"); 7 | } 8 | } 9 | class B extends Thread{ 10 | public void run(){ 11 | for(int i = 0 ; i<=5; i++){ 12 | System.out.println("From thread B = i " + i); 13 | } 14 | System.out.println("Exit from B"); 15 | } 16 | } 17 | 18 | class C extends Thread{ 19 | public void run(){ 20 | for(int i = 0 ; i<=5; i++){ 21 | System.out.println("From thread C = i " + i); 22 | } 23 | System.out.println("Exit from C"); 24 | } 25 | } 26 | 27 | class ThreadDemo { 28 | 29 | public static void main(String Args[]){ 30 | A thread = new A(); 31 | thread.start(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 kriticalflare 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /GUI/gui.java: -------------------------------------------------------------------------------- 1 | import javax.swing.*; 2 | import java.awt.event.ActionEvent; 3 | import java.awt.event.ActionListener; 4 | 5 | class gui{ 6 | public static void main(String[] args) { 7 | 8 | JFrame f1=new JFrame("simple"); 9 | JLabel l1=new JLabel("ENTER NAME"); 10 | JTextField t=new JTextField(); 11 | JLabel l2=new JLabel(); 12 | JButton b=new JButton("CLICK"); 13 | f1.setSize(500,500); 14 | l1.setBounds(210,50,200,100); 15 | t.setBounds(150,120,200,20); 16 | b.setBounds(210,150,90,50); 17 | f1.add(l1); 18 | f1.add(t); 19 | f1.add(b); 20 | b.addActionListener( 21 | 22 | new ActionListener(){ 23 | @Override 24 | public void actionPerformed(ActionEvent e) 25 | { 26 | String str=t.getText(); 27 | l2.setText("hello "+ str +",how are you?"); 28 | } 29 | } 30 | ); 31 | l2.setBounds(180,200,400,100); 32 | f1.add(l2); 33 | f1.setLayout(null); 34 | f1.setVisible(true); 35 | 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /DSA/MergeSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge(int a[], int start, int mid, int end) 4 | { 5 | // Store starts of both the halves 6 | int p = start, q = mid + 1; 7 | int len = end - start + 1; 8 | int arr[len], k = 0; 9 | while (len--) // Loop must run len times to fill all elements 10 | { 11 | if (p > mid) // part1 end? 12 | arr[k++] = a[q++]; 13 | else if (q > end) // part2 end? 14 | arr[k++] = a[p++]; 15 | else 16 | { 17 | // Check which part has bigger element 18 | arr[k++] = (a[p] < a[q]) ? a[p++] : a[q++]; 19 | } 20 | } 21 | // Copy sorted elements 22 | for (int j = 0; j < k; ++j) 23 | { 24 | a[start++] = arr[j]; 25 | } 26 | } 27 | 28 | void mergeSort(int a[], int l, int r) 29 | { 30 | if (l < r) 31 | { 32 | int m = (l + r) / 2; 33 | mergeSort(a, l, m); 34 | mergeSort(a, m + 1, r); 35 | merge(a, l, m, r); 36 | } 37 | } 38 | 39 | void printArr(int *a, int n) 40 | { 41 | for (int i = 0; i < n; ++i) 42 | { 43 | printf("%d ", a[i]); 44 | } 45 | } 46 | 47 | int main() 48 | { 49 | int a[] = {30, -10, 15, 0, 50, 75}; 50 | int n = sizeof(a) / sizeof(a[0]); 51 | mergeSort(a, 0, n - 1); 52 | printArr(a, n); 53 | } 54 | -------------------------------------------------------------------------------- /DSA/BinarySearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int bsiter(int a[], int n, int x) 5 | { 6 | int l = 0, r = n - 1; 7 | while (l <= r) 8 | { 9 | int mid = (l + r) / 2; 10 | if (x == a[mid]) 11 | { 12 | return mid; 13 | } 14 | else if (x < a[mid]) 15 | { 16 | r = mid - 1; 17 | } 18 | else if (x > a[mid]) 19 | { 20 | l = mid + 1; 21 | } 22 | } 23 | return -1; 24 | } 25 | 26 | int bsrec(int a[], int l, int r, int x) 27 | { 28 | if (l >= r) 29 | return -1; 30 | int mid = (l + r) / 2; 31 | if (x == a[mid]) 32 | { 33 | return mid; 34 | } 35 | else if (x < a[mid]) 36 | { 37 | bsrec(a, l, mid - 1, x); 38 | } 39 | else if (x > a[mid]) 40 | { 41 | bsrec(a, mid + 1, r, x); 42 | } 43 | } 44 | 45 | int main() 46 | { 47 | int a[] = {-10, -4, 0, 10, 12, 13, 24, 56, 100}; 48 | int n = sizeof(a) / sizeof(a[0]); 49 | // Search keys 50 | int x[] = {0, -4, 15}; 51 | for (int i = 0; i < 3; ++i) 52 | { 53 | int index = bsiter(a, n, x[i]); 54 | if (index != -1) 55 | printf("%d found at index = %d\n", x[i], index); 56 | else 57 | printf("%d not found\n", x[i]); 58 | } 59 | for (int i = 0; i < 3; ++i) 60 | { 61 | int index = bsrec(a, 0, n - 1, x[i]); 62 | if (index != -1) 63 | printf("%d found at index = %d\n", x[i], index); 64 | else 65 | printf("%d not found\n", x[i]); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /DSA/stack.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #define MAX 30 3 | struct stack 4 | { 5 | int container[MAX]; 6 | int stack_pointer; 7 | } st; 8 | int size() 9 | { 10 | return st.stack_pointer + 1; 11 | } 12 | int peek() 13 | { 14 | return st.container[st.stack_pointer]; 15 | } 16 | void push(int arg) 17 | { 18 | 19 | if(st.stack_pointer < MAX - 1) 20 | st.container[++st.stack_pointer] = arg; 21 | else 22 | printf("Stack overflow\n"); 23 | 24 | } 25 | int pop() 26 | { 27 | 28 | --st.stack_pointer; 29 | if(st.stack_pointer<-1) 30 | 31 | { 32 | ++st.stack_pointer; 33 | 34 | printf("Stack underflow\n"); 35 | } 36 | return st.container[st.stack_pointer+1]; 37 | 38 | } 39 | void display() 40 | { 41 | int tem = st.stack_pointer; 42 | while(st.stack_pointer-- + 1) 43 | { 44 | printf("%d ", st.container[st.stack_pointer+1]); 45 | } 46 | printf("\n"); 47 | st.stack_pointer = tem; 48 | } 49 | int main() 50 | { 51 | int choice = 0, val; 52 | st.stack_pointer = -1; 53 | do { 54 | printf("\n1. PUSH\n2. POP\n3. PEEK\n4. SIZE\n5. DISPLAY\n\n"); 55 | scanf("%d",&choice); 56 | switch (choice) 57 | { 58 | case 1: 59 | printf("Enter value : "); 60 | scanf("%d",&val); 61 | push(val); 62 | break; 63 | case 2: 64 | printf("Popped : %d\n",pop()); 65 | break; 66 | case 3: 67 | 68 | printf("The top element is %d\n",peek()); 69 | break; 70 | case 4: 71 | printf("The size of stack is : %d\n",size()); 72 | break; 73 | case 5: 74 | display(); 75 | break; 76 | } 77 | } while(choice!=0); 78 | return 0; 79 | } -------------------------------------------------------------------------------- /DSA/stacks.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node{ 4 | int data; 5 | struct node * next; 6 | }; 7 | struct node *head,*ptr; 8 | 9 | int top=-1; 10 | 11 | void push(int x) 12 | { 13 | ptr=head; 14 | struct node * newnode =(struct node *)malloc(sizeof(struct node *)); 15 | newnode->data=x; 16 | newnode->next=ptr; 17 | head=newnode; 18 | top++; 19 | } 20 | 21 | int pop() 22 | { 23 | if(top<0) 24 | printf("underflow"); 25 | else 26 | { 27 | printf("the number popped is: "); 28 | ptr=head; 29 | head=head->next; 30 | int v= ptr->data; 31 | free(ptr); 32 | top--; 33 | return v; 34 | } 35 | } 36 | 37 | void display() 38 | { 39 | ptr=head; 40 | while(ptr!=NULL) 41 | { 42 | printf("%d\n",ptr->data); 43 | ptr=ptr->next; 44 | } 45 | } 46 | 47 | void peek() 48 | { 49 | printf("%d\n",head->data); 50 | } 51 | 52 | void size() 53 | { 54 | printf("the size of stack is %d\n",top+1); 55 | } 56 | 57 | int main() { 58 | 59 | int temp; 60 | int op; 61 | do{ 62 | printf("1)push\n2)pop\n3)display\n4)peek\n5)size\n"); 63 | scanf("%d",&op); 64 | switch(op) 65 | { 66 | case 1: 67 | printf("enter a number\n"); 68 | scanf("%d",&temp); 69 | push(temp); 70 | break; 71 | case 2: 72 | printf(" %d\n",pop()); 73 | break; 74 | case 3: 75 | printf("the stack is\n"); 76 | display(); 77 | break; 78 | case 4: 79 | printf("the top number is\n"); 80 | peek(); 81 | break; 82 | case 5: 83 | size(); 84 | } 85 | }while(op>0&op<6); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /DSA/COPY_CON_LL.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int data; 7 | struct node * next; 8 | }; 9 | struct node* head1=NULL; 10 | struct node* head2=NULL; 11 | struct node* ptr1=NULL; 12 | struct node* ptr2=NULL; 13 | struct node* ptr=NULL; 14 | 15 | struct node *Create_list(int size,struct node *head) 16 | { 17 | int i; 18 | for(i=1;i<=size;i++) 19 | { 20 | struct node * newnode=(struct node *)malloc(sizeof(struct node)); 21 | printf("Enter data: "); 22 | scanf("%d",&newnode->data); 23 | newnode->next=NULL; 24 | if(head==NULL) 25 | head=newnode; 26 | else 27 | { 28 | ptr=head; 29 | while(ptr->next!=NULL) 30 | { 31 | ptr=ptr->next; 32 | } 33 | ptr->next=newnode; 34 | } 35 | } 36 | return head; 37 | } 38 | 39 | void Display(struct node *head) 40 | { 41 | ptr=head; 42 | while(ptr!=NULL) 43 | { 44 | printf("%d ",ptr->data); 45 | ptr=ptr->next; 46 | } 47 | } 48 | 49 | void copy(int m, int n) 50 | { 51 | if(m>n) 52 | printf("Copy Operation is not possible"); 53 | else 54 | { 55 | struct node *ptr1=head1; 56 | struct node *ptr2=head2; 57 | while(ptr2!=NULL) 58 | { 59 | ptr1->data=ptr2->data; 60 | ptr1=ptr1->next; 61 | ptr2=ptr2->next; 62 | } 63 | } 64 | Display(head1); 65 | } 66 | 67 | void Split(pos) 68 | { 69 | ptr=head1; 70 | while(--pos) 71 | { 72 | ptr=ptr->next; 73 | } 74 | head2=ptr->next; 75 | ptr->next=NULL; 76 | } 77 | 78 | void concat() 79 | { 80 | ptr1=head1; 81 | while(ptr1->next!=NULL) 82 | { 83 | ptr1=ptr1->next; 84 | } 85 | ptr1->next=head2; 86 | Display(head1); 87 | } 88 | 89 | 90 | int main() 91 | { 92 | int ch,n,m,pos; 93 | while(ch!=6) 94 | { 95 | printf("\nMenu\n"); 96 | printf("1. Create List \n"); 97 | printf("2. Copy \n"); 98 | printf("3. Split \n"); 99 | printf("4. Concatenate \n"); 100 | printf("5. Display\n"); 101 | printf("6. EXIT\n"); 102 | printf("Enter Your Choice: "); 103 | scanf("%d",&ch); 104 | switch(ch) 105 | { 106 | case 1: 107 | printf("\nEnter No of Nodes of first linked list: "); 108 | scanf("%d",&n); 109 | head1=Create_list(n,head1); 110 | printf("\nEnter No of Nodes of Second linked list: "); 111 | scanf("%d",&m); 112 | head2=Create_list(m,head2); 113 | break; 114 | case 2: 115 | copy(m,n); 116 | break; 117 | case 3: 118 | printf("\nSplitPos: "); 119 | scanf("%d",&pos); 120 | Split(pos); 121 | break; 122 | case 4: 123 | concat(); 124 | break; 125 | case 5: 126 | printf("\nLIST 1 "); 127 | Display(head1); 128 | printf("\nLIST 2 "); 129 | Display(head2); 130 | break; 131 | default:break; 132 | } 133 | } 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /DSA/linkedlist.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #include <stdlib.h> 3 | typedef struct node { 4 | int data; 5 | struct node* next; 6 | } node; 7 | node *head1 = NULL, *head2 = NULL, *ptr = NULL,*tem = NULL, *ptr2 = 8 | NULL,*head3 = NULL; 9 | void add(node** head); 10 | void display(node* head); 11 | void concatenate(); 12 | void add(node** head) 13 | { 14 | int n, m; 15 | printf("Enter size of list : "); 16 | scanf("%d",&n); 17 | for(int i=0;i<n;++i) 18 | 19 | { 20 | printf("Enter element : "); 21 | scanf("%d",&m); 22 | node* newnode = (node*)malloc(sizeof(node)); 23 | newnode->data = m; 24 | newnode->next = NULL; 25 | if(*head==NULL) 26 | { 27 | *head = newnode; 28 | ptr = *head; 29 | } 30 | else 31 | { 32 | ptr->next = newnode; 33 | ptr = newnode; 34 | } 35 | } 36 | } 37 | void concatenate() 38 | { 39 | ptr = head1; 40 | while(ptr->next!=NULL) 41 | { 42 | ptr = ptr->next; 43 | } 44 | ptr2 = head2; 45 | while(ptr2!=NULL) 46 | { 47 | node* newnode = (node*)malloc(sizeof(node)); 48 | newnode->data = ptr2->data; 49 | newnode->next = ptr2->next; 50 | ptr->next = newnode; 51 | ptr = ptr->next; 52 | ptr2 = ptr2->next; 53 | 54 | } 55 | } 56 | void display(node* head) 57 | { 58 | node* ptr = head; 59 | while(ptr!=NULL) 60 | { 61 | printf("%d ",ptr->data); 62 | ptr = ptr->next; 63 | } 64 | printf("\n"); 65 | } 66 | void split(node** head) 67 | { 68 | int ind; 69 | printf("Enter number of elements to be kept: "); 70 | scanf("%d", &ind); 71 | ptr = *head; 72 | while(ind-- - 1) 73 | { 74 | ptr = ptr->next; 75 | } 76 | ptr->next = NULL; 77 | } 78 | int size(node* head) 79 | { 80 | int m = 0; 81 | ptr = head; 82 | while(ptr!=NULL && ++m); 83 | return m; 84 | } 85 | 86 | void copy() 87 | { 88 | int m= size(head1), n = size(head2); 89 | if(m<n) 90 | printf("Cant copy"); 91 | else 92 | { 93 | ptr = head1; 94 | ptr2 = head2; 95 | while(ptr2!=NULL) 96 | { 97 | ptr->data = ptr2->data; 98 | ptr = ptr->next; 99 | ptr2 = ptr2->next; 100 | } 101 | } 102 | } 103 | int main() 104 | { 105 | int choice = 0; 106 | do 107 | { 108 | printf("1. Add to linked list 1\n"); // done 109 | printf("2. Add to linked list 2\n"); //done 110 | printf("3. Copy L1 to L2\n"); 111 | printf("4. Concatenate L1 to L2\n"); //done 112 | printf("5. Split L1\n"); //done 113 | printf("6. Split L2\n"); //done 114 | printf("7. Display L1\n"); //done 115 | printf("8. Display L2\n"); //done 116 | printf("0. Exit\n\n"); //done 117 | scanf("%d",&choice); 118 | 119 | switch(choice) 120 | { 121 | case 1: 122 | add(&head1); 123 | break; 124 | case 2: 125 | add(&head2); 126 | break; 127 | case 3: 128 | copy(); 129 | break; 130 | case 4: 131 | concatenate(); 132 | break; 133 | case 5: 134 | split(&head1); 135 | break; 136 | case 6: 137 | split(&head2); 138 | break; 139 | case 7: 140 | display(head1); 141 | break; 142 | case 8: 143 | display(head2); 144 | break; 145 | } 146 | } 147 | while(choice!=0); 148 | } -------------------------------------------------------------------------------- /DSA/deque.c: -------------------------------------------------------------------------------- 1 | #include <stdio.h> 2 | #include <stdlib.h> 3 | #define MAX 4 4 | int deque_arr[MAX]; 5 | int left = -1, right = -1; 6 | void insert_right() 7 | { 8 | if((left == 0 && right == MAX-1) || (left == right+1)) 9 | { 10 | printf("Queue Overflow\n"); 11 | return; 12 | } 13 | if(left == -1) 14 | { 15 | left = right = 0; 16 | } 17 | else if(right == MAX-1) 18 | right = 0; 19 | else 20 | ++right; 21 | printf("Enter the element value : "); 22 | int val; 23 | scanf("%d", &val); 24 | 25 | deque_arr[right] = val; 26 | } 27 | void insert_left() 28 | { 29 | if((left == 0 && right == MAX-1) || (left == right+1)) 30 | { 31 | printf("Queue Overflow\n"); 32 | return; 33 | } 34 | if(left == -1) 35 | { 36 | left = right = 0; 37 | } 38 | else if(left == 0) 39 | left = MAX-1; 40 | else 41 | --left; 42 | printf("Enter the element value : "); 43 | int val; 44 | scanf("%d", &val); 45 | deque_arr[left] = val; 46 | } 47 | void delete_left() 48 | { 49 | if(left == -1) 50 | { 51 | printf("Queue is empty\n"); 52 | return ; 53 | } 54 | printf("Deleted : %d\n",deque_arr[left]); 55 | if(left == right) 56 | { 57 | left = -1; 58 | 59 | right = -1; 60 | } 61 | else if (left == MAX-1) 62 | left = 0; 63 | else 64 | ++left; 65 | 66 | } 67 | void delete_right() 68 | { 69 | if(left == -1) 70 | { 71 | printf("Queue is empty\n"); 72 | return ; 73 | } 74 | printf("Deleted : %d\n",deque_arr[right]); 75 | if(left == right) 76 | { 77 | left = -1; 78 | right = -1; 79 | } 80 | else if (right == 0) 81 | right = MAX - 1; 82 | else 83 | --right; 84 | 85 | } 86 | void display() 87 | { 88 | if(left == -1) 89 | { 90 | printf("Queue is empty\n"); 91 | return; 92 | } 93 | printf("The queue is : \n"); 94 | 95 | if(left <= right) 96 | { 97 | for(int i=left;i<=right;++i) 98 | printf("%d ",deque_arr[i]); 99 | 100 | } 101 | else 102 | { 103 | for(int i=left;i<MAX;++i) 104 | printf("%d ",deque_arr[i]); 105 | for(int i=0;i<=right;++i) 106 | printf("%d ",deque_arr[i]); 107 | 108 | } 109 | printf("\n"); 110 | } 111 | int size() 112 | { 113 | int count = 0; 114 | if(left == -1) 115 | { 116 | return 0; 117 | } 118 | if(left <= right) 119 | { 120 | for(int i=left;i<=right;++i) 121 | ++count; 122 | 123 | } 124 | else 125 | { 126 | for(int i=left;i<MAX;++i) 127 | ++count; 128 | for(int i=0;i<=right;++i) 129 | ++count; 130 | 131 | } 132 | return count; 133 | } 134 | int main() 135 | { 136 | int choice = 0; 137 | do { 138 | printf("1. Insert left\n2. Insert right\n3. Delete left\n4. Delete right\n5. 139 | Size\n6. Display\n0. Exit\n\n"); 140 | scanf("%d",&choice); 141 | switch (choice) 142 | { 143 | case 1: 144 | insert_left(); 145 | break; 146 | case 2: 147 | insert_right(); 148 | break; 149 | case 3: 150 | delete_left(); 151 | break; 152 | case 4: 153 | delete_right(); 154 | break; 155 | case 5: 156 | printf("The size of queue is : %d\n",size()); 157 | break; 158 | case 6: 159 | display(); 160 | break; 161 | } 162 | } while(choice!=0); 163 | 164 | return 0; 165 | } -------------------------------------------------------------------------------- /DSA/L_Limplement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node 4 | { 5 | int data; 6 | struct node *next; 7 | }; 8 | struct node * head=NULL,*ptr; 9 | void display() 10 | { 11 | 12 | ptr=head; 13 | while(ptr!=NULL) 14 | { 15 | printf("%d ",(ptr->data)); 16 | ptr=ptr->next; 17 | } 18 | } 19 | void create_list(int n) 20 | { 21 | int i; 22 | for(i=0;idata); 27 | newnode->next=NULL; 28 | if(head == NULL) 29 | { 30 | head=newnode; 31 | ptr=head; 32 | } 33 | else 34 | { 35 | ptr->next=newnode; 36 | ptr=ptr->next; 37 | } 38 | } 39 | } 40 | void insert_beg() 41 | { 42 | struct node * newnode =(struct node *)malloc(sizeof(struct node *)); 43 | printf("enter no"); 44 | scanf("%d",&newnode->data); 45 | newnode->next=NULL; 46 | ptr=head; 47 | head=newnode; 48 | newnode->next=ptr; 49 | } 50 | void insert_end() 51 | { 52 | struct node * newnode =(struct node *)malloc(sizeof(struct node *)); 53 | printf("enter no"); 54 | scanf("%d",&newnode->data); 55 | newnode->next=NULL; 56 | ptr=head; 57 | while(ptr->next!=NULL) 58 | { 59 | ptr=ptr->next; 60 | } 61 | ptr->next=newnode; 62 | } 63 | void insert_mid() 64 | { 65 | int n,i=1; 66 | struct node * newnode =(struct node *)malloc(sizeof(struct node *)); 67 | printf("enter no"); 68 | scanf("%d",&newnode->data); 69 | newnode->next=NULL; 70 | printf("\nenter the index"); 71 | scanf("%d",&n); 72 | ptr=head; 73 | while(inext; 76 | i++; 77 | } 78 | newnode->next=ptr->next; 79 | ptr->next=newnode; 80 | 81 | 82 | } 83 | void delete_end() 84 | { 85 | ptr=head->next; 86 | struct node*prev=head; 87 | while(ptr->next!=NULL) 88 | { 89 | ptr=ptr->next; 90 | prev=prev->next; 91 | } 92 | free(ptr); 93 | prev->next=NULL; 94 | } 95 | void delete_beg() 96 | { 97 | ptr=head; 98 | head=head->next; 99 | free(ptr); 100 | } 101 | void delete_mid() 102 | { 103 | int n,i=1; 104 | printf("\nenter the index"); 105 | scanf("%d",&n); 106 | ptr=head->next; 107 | struct node* prev=head; 108 | while(inext; 111 | prev=prev->next; 112 | i++; 113 | } 114 | prev->next=ptr->next; 115 | free(ptr); 116 | 117 | } 118 | void size() 119 | { 120 | int count=0; 121 | ptr=head; 122 | while(ptr!=NULL) 123 | { 124 | ptr=ptr->next; 125 | count++; 126 | } 127 | printf("\nsize is %d \n",count); 128 | } 129 | void reverse() 130 | { 131 | ptr=head; 132 | struct node * prev=NULL,*post=NULL; 133 | while(ptr!=NULL) 134 | { 135 | post=ptr->next; 136 | ptr->next=prev; 137 | prev=ptr; 138 | ptr=post; 139 | } 140 | head=prev; 141 | 142 | } 143 | void main() 144 | { 145 | printf("MENU:-\n"); 146 | printf("1.create a list\n"); 147 | printf("2.insersion at end\n"); 148 | printf("3.insersion at beg\n"); 149 | printf("4.insersion at mid\n"); 150 | printf("5.delete at end\n"); 151 | printf("6.delete at beg\n"); 152 | printf("7.delete at mid\n"); 153 | printf("8.display\n"); 154 | printf("9.size\n"); 155 | printf("10.reverse\n"); 156 | printf("11.exit\n"); 157 | label: 158 | printf("enter your choice\n"); 159 | int a,n; 160 | scanf("%d",&a); 161 | switch(a) 162 | { 163 | case 1:printf("enter no of nodes"); 164 | scanf("%d",&n); 165 | create_list(n); 166 | break; 167 | case 2:insert_end(); 168 | display(); 169 | break; 170 | 171 | case 3:insert_beg(); 172 | display(); 173 | break; 174 | 175 | case 4:insert_mid(); 176 | display(); 177 | break; 178 | case 5:delete_end(); 179 | display(); 180 | break; 181 | case 6:delete_beg(); 182 | display(); 183 | break; 184 | 185 | case 7:delete_mid(); 186 | display(); 187 | break; 188 | case 8:display(); 189 | break; 190 | case 9: size(); 191 | break; 192 | case 10: reverse(); 193 | display(); 194 | break; 195 | case 11:printf("\n exit"); 196 | exit(0); 197 | 198 | } 199 | goto label; 200 | } 201 | -------------------------------------------------------------------------------- /JAVA/matrix/matrix.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class a 3 | { 4 | public int[][] creatematrix(int r, int c) { 5 | Scanner in=new Scanner(System.in); 6 | int[][] a=new int[r][c]; 7 | System.out.println("enter the matrix"); 8 | for(int i=0;i