```mlx % subplot(2, 2, 1); t = linspace(-10, 10); xt = t; plot(t, xt); % % grid on; % % subplot(2, 2, 2); t = linspace(-10, 10); xt = t + 5; plot(t, xt); % xticks([]); % % grid on; % % subplot(2, 2, 3); t = linspace(-2 * pi, 2 * pi); xt = cos(t); plot(t, % xt); xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi]); % xticklabels({'-2*pi', '-3*pi/2', '-pi', '-pi/2', '0', 'pi/2', 'pi', % '3*pi/2', '2*pi'}); % % grid on; % % subplot(2, 2, 4); t = linspace(-2 * pi, 2 * pi); xt = sin(t); plot(t, % xt); xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi]); % xticklabels({'-2*pi', '-3*pi/2', '-pi', '-pi/2', '0', 'pi/2', 'pi', % '3*pi/2', '2*pi'}); % % grid on; % subplot(2, 1, 1); % t = linspace(-2 * pi, 2 * pi); % xt = cos(t); % plot(t, xt); % xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi]); % xticklabels({'-2*pi', '-3*pi/2', '-pi', '-pi/2', '0', 'pi/2', 'pi', '3*pi/2', '2*pi'}); % title('cosine wave'); % yl = ylim; % line([0, 0], yl); % xl = xlim; % line(xl, [0, 0]); % % grid on; % % subplot(2, 1, 2); % t = linspace(-2 * pi, 2 * pi); % xt = sin(t); % plot(t, xt); % xticks([-2*pi -3*pi/2 -pi -pi/2 0 pi/2 pi 3*pi/2 2*pi]); % xticklabels({'-2*pi', '-3*pi/2', '-pi', '-pi/2', '0', 'pi/2', 'pi', '3*pi/2', '2*pi'}); % title('sine wave'); % yl = ylim; % line([0, 0], yl); % xl = xlim; % line(xl, [0, 0]); % % grid on; subplot(3, 1, 1); t = linspace(0, 4 * pi); xt = exp(i*t); plot(t, xt); grid on subplot(3, 1, 2); t = linspace(0, 4 * pi); xt = exp(i*t); plot(t, real(xt)); grid on subplot(3, 1, 3); t = linspace(0, 4 * pi); xt = exp(i*t); plot(t, imag(xt)); grid on figure plot3(t, real(xt), imag(xt)); grid on ```

Binary Search Tree (BTS) in Java and some of its common methods

Tags: data, binarysearchtree, java, bts, programming, datastructure, structure

Values of keys in the left sub-tree of the root should be smaller than or equal to the values of the key at the root and the keys in the right sub-tree of the root should be larger than or equal to the values of the key at the root. The left and right subtree each must also be a binary search tree.

What is JSON and what are the advantages of it

Tags: programming, json, developer

JSON is a language-independent data format. It was derived from JavaScript, it stands for JavaScript Object Notation and it is often used when data is sent from a server to a web page

LinkedList in Java and some of its common methods

Tags: data, java, programming, linkedlist, structure, data-structure

a linear data structure where the elements are not stored in contiguous locations and every element is a separate object with a data part and address part. The elements are linked using pointers and addresses. Each element is known as a node. Due to the dynamicity and ease of insertions and deletions, they are preferred over the arrays. It also has a few disadvantages like the nodes cannot be accessed directly instead we need to start from the head and follow through the link to reach a node we wish to access.

```java /* * * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication17; /** * * @author FUE */ public class Node { int data; Node next ; public Node(int data) { this.data=data; next=null; } } ``` ```java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication17; /** * * @author FUE */ public class linkedlist { Node head ; int elementscount; public linkedlist() { head=null; elementscount=0; } boolean Isempty() { return (elementscount==0); } void insertFirst(int data) { Node mynode = new Node(data); // mynode. if(Isempty()) { head=mynode; } else { mynode.next=head; head=mynode; } elementscount++; } void insertLast(int data) { Node mynode = new Node(data); if(Isempty()) { head=mynode; } else { Node temp =head; while(temp.next!=null) { temp=temp.next; } temp.next=mynode; } elementscount++; } int removeFirst() { int val ; if(head.next==null) { val=head.data; head=null; } else { val=head.data; head=head.next; } elementscount--; return val; } int removeLast() { int val ; if(head.next==null) { val=head.data; head=null; } else { Node temp=head; while (temp.next.next!=null) { temp =temp.next; } val=temp.next.data; temp.next=null; } elementscount--; return val; } int Count() { return elementscount; } void printLinkedlist() { Node temp=head; while (temp!=null) { System.out.println(temp.data); temp=temp.next; } } void insertAt (int index , int data) { Node mynode = new Node(data); if(index==0) { if(Isempty()) { head=mynode; } else { mynode.next=head; head=mynode; } } else { Node temp=head; for(int i=0; i < index-1;i++) { temp=temp.next; } mynode.next=temp.next; temp.next=mynode; } elementscount++; } int deleteAt (int index) { int val ; if(index==0) { if(head.next==null) { val=head.data; head=null; } else { val=head.data; head=head.next; } } else { Node temp=head; //Node tobedeleted; for(int i=0; i < index-1;i++) { temp=temp.next; } val=temp.next.data; temp.next=temp.next.next; } elementscount--; return val; } } ``` ```java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication17; /** * * @author FUE */ public class MyStack { int arr[]; int numberofelements; int stacktop; int maxsize; public MyStack (int maxsize) { this.maxsize=maxsize; arr= new int[maxsize]; stacktop=-1; numberofelements=0; } boolean isfull() { return numberofelements==maxsize; } void push(int element) { if(!isfull()) { stacktop++; arr[stacktop]=element; numberofelements++; } else { System.out.println("stack is full"); } } boolean isempty() { return stacktop==-1; } void pop () { if(!isempty()) { int poppednumber=arr[stacktop]; stacktop--; System.out.println("The number you popped is" + poppednumber); } else { System.out.println("Stack is empty !!!"); } } void print () { for(int i=stacktop; i>0 ; i--) { System.out.println(arr[i]); } } } ```

```java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javaapplication17; /** * * @author FUE */ public class JavaApplication17 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } public static class Node { int data; Node next ; public Node(int data) { this.data=data; next=null; } } public static class linkedlist { Node head ; int elementscount; public linkedlist() { head=null; elementscount=0; } boolean Isempty() { return (elementscount==0); } void insertFirst(int data) { Node mynode = new Node(data); // mynode. if(Isempty()) { head=mynode; } else { mynode.next=head; head=mynode; } elementscount++; } void insertLast(int data) { Node mynode = new Node(data); if(Isempty()) { head=mynode; } else { Node temp =head; while(temp.next!=null) { temp=temp.next; } temp.next=mynode; } elementscount++; } int removeFirst() { int val ; if(head.next==null) { val=head.data; head=null; } else { val=head.data; head=head.next; } elementscount--; return val; } int removeLast() { int val ; if(head.next==null) { val=head.data; head=null; } else { Node temp=head; while (temp.next.next!=null) { temp =temp.next; } val=temp.next.data; temp.next=null; } elementscount--; return val; } int Count() { return elementscount; } void printLinkedlist() { Node temp=head; while (temp!=null) { System.out.println(temp.data); temp=temp.next; } } void insertAt (int index , int data) { Node mynode = new Node(data); if(index==0) { if(Isempty()) { head=mynode; } else { mynode.next=head; head=mynode; } } else { Node temp=head; for(int i=0; i < index-1;i++) { temp=temp.next; } mynode.next=temp.next; temp.next=mynode; } elementscount++; } int deleteAt (int index) { int val ; if(index==0) { if(head.next==null) { val=head.data; head=null; } else { val=head.data; head=head.next; } } else { Node temp=head; //Node tobedeleted; for(int i=0; i < index-1;i++) { temp=temp.next; } val=temp.next.data; temp.next=temp.next.next; } elementscount--; return val; } } } ```

Test ```cpp #include <windows.h> #include <gl/gl.h> #include <gl/glut.h> #include <ctime> #include <cstdio> #include<synchapi.h> using namespace std; #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") #pragma comment(lib, "glut32.lib") /*** Global Variables ***/ float fXpos = 0, fYpos = 0, fRot = 0, fScale = 1; /** Creates the main window, registers event handlers, and initializes OpenGL stuff. */ void InitGraphics(int argc, char* argv[]); void OnKeyPress(unsigned char key, int x, int y); void OnSpecialKeyPress(int key, int x, int y); /** Sets the logical coordinate system we will use to specify our drawings. */ void SetTransformations() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-100, 100, -100, 100); } void Draw_Cordinates() { glLineWidth(5); glBegin(GL_LINES); glColor3f(0, 1, 0); // X-axis glVertex3f(-100, 0, 0); glVertex3f(100, 0, 0); //Y-axis glVertex3f(0, -100, 0); glVertex3f(0, 100, 0); glEnd(); } void OnDisplay() { //set the background color to white glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT); SetTransformations(); Draw_Cordinates(); glTranslatef(fXpos, fYpos, 0); glRotatef(fRot, 0, 0, 1); glScalef(fScale, fScale, 0); glBegin(GL_QUADS); glColor3f(1, 0, 0); glVertex2f(-50, -50); glVertex2f(50, -50); glVertex2f(50, 50); glVertex2f(-50, 50); glEnd(); glFlush(); glutSwapBuffers(); glutPostRedisplay(); } /** Creates the main window, registers event handlers, and initializes OpenGL stuff. */ void InitGraphics(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(550, 100); //pass (-1, -1) for Window-Manager defaults glutInitWindowSize(800, 600); glutCreateWindow("OpenGL Lab"); glutDisplayFunc(OnDisplay); glutIdleFunc(OnDisplay); glutKeyboardFunc(OnKeyPress); glutSpecialFunc(OnSpecialKeyPress); glutMainLoop(); } int main(int argc, char* argv[]) { InitGraphics(argc, argv); return 0; } void OnKeyPress(unsigned char key, int x, int y) { if (key == 27) { exit(0); } switch (key) { case 'a': case 'A': { fXpos -= 2; break; } case 'd': case 'D': { fXpos += 2; break; } case 'w': case 'W': { fYpos += 2; break; } case 's': case 'S': { fYpos -= 2; break; } case 'e': case 'E': { fRot -= 0.9; break; } case 'q': case 'Q': { fRot += 0.9; break; } default: break; } }; void OnSpecialKeyPress(int key, int x, int y) {}; ```

```cpp #include <windows.h> #include <gl/gl.h> #include <gl/glut.h> #include <ctime> #include <cstdio> #include<synchapi.h> using namespace std; #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") #pragma comment(lib, "glut32.lib") /*** Global Variables ***/ float fXpos = 0, fYpos = 0, fRot = 0, fScale = 1; /** Creates the main window, registers event handlers, and initializes OpenGL stuff. */ void InitGraphics(int argc, char* argv[]); void OnKeyPress(unsigned char key, int x, int y); void OnSpecialKeyPress(int key, int x, int y); /** Sets the logical coordinate system we will use to specify our drawings. */ void SetTransformations() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-100, 100, -100, 100); } void Draw_Cordinates() { glLineWidth(5); glBegin(GL_LINES); glColor3f(0, 1, 0); // X-axis glVertex3f(-100, 0, 0); glVertex3f(100, 0, 0); //Y-axis glVertex3f(0, -100, 0); glVertex3f(0, 100, 0); glEnd(); } void OnDisplay() { //set the background color to white glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT); SetTransformations(); Draw_Cordinates(); // glPushMatrix(); glTranslatef(fXpos, fYpos, 0); glRotatef(fRot, 0, 0, 1); glScalef(fScale, fScale, 0); glBegin(GL_QUADS); glColor3f(1, 0, 0); glVertex2f(-50, -50); glVertex2f(50, -50); glVertex2f(50, 50); glVertex2f(-50, 50); glEnd(); // glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostRedisplay(); } /** Creates the main window, registers event handlers, and initializes OpenGL stuff. */ void InitGraphics(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowPosition(550, 100); //pass (-1, -1) for Window-Manager defaults glutInitWindowSize(800, 600); glutCreateWindow("OpenGL Lab"); glutDisplayFunc(OnDisplay); glutIdleFunc(OnDisplay); glutKeyboardFunc(OnKeyPress); glutSpecialFunc(OnSpecialKeyPress); glutMainLoop(); } int main(int argc, char* argv[]) { InitGraphics(argc, argv); return 0; } void OnKeyPress(unsigned char key, int x, int y) { if (key == 27) { exit(0); } switch (key) { case 'a': case 'A': { fXpos -= 2; break; } case 'd': case 'D': { fXpos += 2; break; } case 'w': case 'W': { fYpos += 2; break; } case 's': case 'S': { fYpos -= 2; break; } case 'e': case 'E': { fRot -= 0.9; break; } case 'q': case 'Q': { fRot += 0.9; break; } default: break; } }; void OnSpecialKeyPress(int key, int x, int y) { switch (key) { case GLUT_KEY_LEFT: { fXpos -= 2; break; } case GLUT_KEY_RIGHT: { fXpos += 2; break; } case GLUT_KEY_UP: { fYpos += 2; break; } case GLUT_KEY_DOWN: { fYpos -= 2; break; } default: break; } }; ```

Not Signed up?

/