2017 universities Ranking in Pakistan

Here are overall top universities of Pakistan.Some universities are at the top place in engineering fields but others are at Applied science, BA and in IT programs

Binary Search in C++

Search found at index

Quick sorting program

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Tree traversal (preorder,inorder,postorder) using linklist (c++)

Tree traversal (preorder,inorder,postorder) using linklist (c++)

Wednesday, 20 February 2019

Use of Objects in Java (Basic Program)



The below program we created three files named as Client, Student, and Marker. We declare the main method in Client class. The objective of this program is to show you the use of objects in java.
For Compilation Javac -d . Client.java  is used. And for execution Java Client is used.

Student.java


package Student;

public class Student
{
public int age;
public String name;
public int id;

}

Marker.java

package Marker;

public class Marker
{
    public String color;
public boolean type;
public int inkLevel;
}

Client.java

package Client;
import Marker.*;
import Student.*;
import java.util.Scanner;
public class Client
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
int y;
int z;
System.out.println("How many students data you want to store:");
y=s.nextInt();
Student x[]=new Student[y];

for(int i=0;i<y;i++)
{
x[i]=new Student();
System.out.println("Enter your age:");
x[i].age=s.nextInt();
System.out.println("\n Enter your name:");
x[i].name=s.next();
System.out.println("\n Enter your Id:");
x[i].id=s.nextInt();
}
System.out.println("How many markers data you want to store:");
z=s.nextInt();
        Marker m[]=new Marker[z];

for(int i=0;i<z;i++)
{
m[i]=new Marker();
System.out.println("Enter Marker color:");
m[i].color=s.next();
System.out.println("Enter Marker type:");
m[i].type=s.nextBoolean();
System.out.println("Enter Marker Inklevel:");
m[i].inklevel=s.nextInt();
}
System.out.println("\n Printing Student data");
for(int i=0;i<y;i++)
{
System.out.println(x[i].id);
System.out.println(x[i].name);
System.out.println(x[i].age);
}
System.out.println("\n Printing Marker data");
for(int i=0;i<z;i++)
{
System.out.println(m[i].type);
System.out.println(m[i].color);
System.out.println(m[i].inklevel);
}
}
}

Wednesday, 6 February 2019

Three Dimension Array in Java (Simple program)



import java.util.Scanner;

public class ThreeDArray
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number of Pages:");
int p=s.nextInt();
System.out.println("Enter number of rows:");
int r=s.nextInt();
System.out.println("Enter number of colums:");
int c=s.nextInt();

int arr[][][]=new int[p][r][c];

System.out.println("Enter numbers in Three dimentional Array:");

for(int j=0;j<arr.length;j++)
for(int i=0;i<arr.length;i++)
for(int k=0;k<arr.length;k++)
{
arr[i][j][k]=s.nextInt();
}
System.out.println("printing");

for(int j=0;j<arr.length;j++)
for(int i=0;i<arr.length;i++)
for(int k=0;k<arr.length;k++)
{
System.out.println(arr[i][j][k]);
}
}
}

Two Dimension Arrays in Java (Simple program)



import java.util.Scanner;
public class TwoDArray
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number of rows:");
int a=s.nextInt();
System.out.println("Enter number of colums:");
int b=s.nextInt();
int arr[][]=new int[a][b];

System.out.println("Enter numbers in Two dimentional Array:");

for(int j=0;j<arr.length;j++)
for(int i=0;i<arr.length;i++)
{
arr[i][j]=s.nextInt();
}

System.out.println("Printing");
for(int j=0;j<arr.length;j++)
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i][j]);
}
}
}

One Dimention Arrays in JAVA Simple Program



import java.util.Scanner;
public class SingleArray
{
public static void main(String []args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter size of an array:");
int x=s.nextInt();
int arr[]=new int[x];
System.out.println("Enter Numbers in an array:");
for(int i=0;i<arr.length;i++)
{
arr[i]=s.nextInt();
}
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
}
}

Sunday, 23 December 2018

Tree traversal (preorder,inorder,postorder) using linklist (c++)



#include<iostream>
using namespace std;

struct node
{
    int data;
    struct node *left;
    struct node *right;
};

/**********Element insertion*****************/

node* insert(node *root,int data)
{
    if(root==NULL)
    {
        root=new node();
        root->data=data;
        root->left=root->right=NULL;
    }
    else if(data<=root->data)
    {
        root->left=insert(root->left,data);
    }
    else
    {
        root->right=insert(root->right,data);
    }
    return root;
}

/*************Printing in preorder*************/

void preorder(node *root)
{
    if(root==NULL)
    return;

    cout<<" "<<root->data;
    preorder(root->left);
    preorder(root->right);
}

/**************printing in inorder************/

void inorder(node *root)
{
    if(root==NULL)
    return;

    inorder(root->left);
    cout<<" "<<root->data;
    inorder(root->right);
}

/**********printing in postorder************/

void postorder(node *root)
{
    if(root==NULL)
    return;
    postorder(root->left);
    postorder(root->right);
    cout<<" "<<root->data;

}

/**************Driver Function***********/
int main()
{
    node *root=NULL;

    root=insert(root,10);
    root=insert(root,20);
    root=insert(root,30);
    root=insert(root,15);
    root=insert(root,9);
    root=insert(root,25);


    cout<<"\n preorder"<<endl;
    preorder(root);
    cout<<"\n Inorder"<<endl;
    inorder(root);
    cout<<"\n Postorder"<<endl;
    postorder(root);
    cout<<endl;


    return 0;
}

output:


Saturday, 22 December 2018

Implementation of queue using linklist (C++)


#include<iostream>
using namespace std;

struct queue
{
    int data;
    struct queue *next;
};

 queue *front=NULL;
 queue *rear=NULL;
    int count=0;
/**********Inserting Element in Queue******************/
void enqueue(int x)
{
  queue *temp;
  temp=new queue();
  temp->data=x;
  temp->next=NULL;
  if(front==NULL && rear==NULL)
  {
      front=rear=temp;
      count++;
  }
  else
  {
      rear->next=temp;
      rear=temp;
      count++;
  }
}
/*********displaying elements in Queue********************/

void display(int count)
{
    queue *temp;
    temp=front;
    for(int i=0;i<count;i++)
    {
        cout<<temp->data<<" ";
        temp=temp->next;
    }
}
/*******Removing element from Queue*********************/

void dequeue()
{
    if(front==NULL)
    {
        cout<<"Queue is empty"<<endl;
    }
    else
    {
        queue *temp;
        temp=front;
        front=front->next;
        delete temp;
        count--;

        cout<<" \n Item Dequeued Successfully"<<endl;
    }
}

/****************Driver Function************************/

int main()
{
    int choice;
    int x;
    do
    {
        cout<<"Enter element is Queue :"<<endl;
        cin>>x;
        enqueue(x);


    cout<<"Do you want to enQueue again?"<<endl;
    cin>>choice;
    }while(choice==1);

    cout<<"After Enqueue"<<endl;
    display(count);

    do
    {
    dequeue();
    cout<<"Do you want to DeQueue again?"<<endl;
    cin>>choice;
    }while(choice==1);

    cout<<"After dequeue"<<endl;
    display(count);

    return 0;

}

Sunday, 16 December 2018

Circular queue using array(insertion, deletion)


#include <iostream>
using namespace std;

int Q[10];
int size=10;
int count=0;
int rear=0;
int front=0;
void enQ(int element)
{
   if(count==size)
   {
       cout<<"Queue Overflow"<<endl;
   }
   else
   {
       Q[rear]=element;
       rear=(rear+1)%size;
       count++;
   }
}
void DeQ()
{
    if(count==0)
    {
        cout<<"Under Flow"<<endl;
    }
    else
    {
        Q[front]=0;
        front=(front+1)%size;
        count--;
    }
}
bool isempty()
{
    if(count==0)
    {
        return true;
    }
}

int main()
{
    int element;
    int e;

    if(isempty()==true)
    {
        cout<<"Queue is empty"<<endl;
    }
    /*************Enqueue*************/
    do
    {
    cout<<"Enter element in queue:"<<endl;
    cin>>element;
    enQ(element);
    cout<<"Do you want enqueue again?" <<endl;
    cin>>e;
    }while(e==1);
    /************display*************/
    cout<<"After inserting value in circular queue"<<endl;
    for(int i=front;i<=count;i++)
    {
        cout<<Q[i]<<" ";
    }
    /***************deletion***************/
    int d;
    cout<<"Do you want to delete from the queue(1=y): "<<endl;
    cin>>d;

    if(d==1)
    {
        int c;
        do
        {

        DeQ();

        cout<<"DO you want to enqueue again?(1=y)"<<endl;
        cin>>c;
        }while(c==1);
    }

    /************display*************/

    cout<<"After Dequeuing"<<endl;
    for(int i=front;i<=count;i++)
    {
        cout<<Q[i]<<" ";
    }

    return 0;
}

Doubly Linklist (insertion,deletion of a node)



#include <iostream>
using namespace std;
struct node2
{
    int data2;
    struct node2 *previous;
    struct node2 *next2;
};
int main()
{
    node2 *head2;
    node2 *last2;
    node2 *temp2;
    last2=0;
    int choice;
    do
    {
    cout<<"Enter data in Doubly node:"<<endl;
    temp2=new node2();
    cin>>temp2->data2;
    if(last2==0)
    {
        temp2->next2=0;
        temp2->previous=0;
        last2=head2=temp2;
    }
    else
    {
        temp2->next2=0;
        temp2->previous=last2;
        last2->next2=temp2;
        last2=temp2;
    }
    cout<<"\nDo you want to create a new node (1=yes,0=NO): ";
    cin>>choice;
    }while(choice==1);
    cout<<"Printing from start"<<endl;
    temp2=head2;
    while(temp2!=0)
    {
      cout<<temp2->data2<<" ";
     temp2=temp2->next2;
    }
    cout<<"\n Printing from end"<<endl;
    temp2=last2;
    while(temp2!=0)
    {
      cout<<temp2->data2<<" ";
     temp2=temp2->previous;
    }
   /******************************************/
       do
    {
    cout<<"Enter data"<<endl;
    temp2=new node2();
    cin>>temp2->data2;
    if(last2==0)
    {
        temp2->next2=0;
        temp2->previous=0;
        last2=head2=temp2;
    }
    else
    {
        temp2->next2=head2;
        temp2->previous=0;
        head2->previous=temp2;
        head2=temp2;
    }
    cout<<"\nDo you want to create a new node (1=yes,0=NO): ";
    cin>>choice;
    }while(choice==1);
    cout<<"\n Printing from start"<<endl;
    temp2=head2;
    while(temp2!=0)
    {
      cout<<temp2->data2<<" ";
     temp2=temp2->next2;
    }
    return 0;
}


Tuesday, 27 November 2018

Singly Linklist in C++ (insertion at satart,middle and end. Searching in linklist. Deletion of any node)


#include <iostream>

using namespace std;

struct node
{
    int data;
    struct node *next;
};

int main()

{
    node *head;
    node *temp;
    node *last;

    last=0;

    int choice;

   do

    {
        temp=new node();
        cout<<"Enter values in a node:"<<endl;
        cin>>temp->data;
        if(last==0)
        {
            head=last=temp;

        }

        else
        {
            last->next=temp;
            last=temp;
        }
        cout<<"Enter your choice:"<<endl;
        cin>>choice;
    }while(choice==1);

        last->next=0;

        temp=head;

        while(temp!=0)

        {
            cout<<temp->data<<" ";
            temp=temp->next;
        }
        /************insertion at the start of the node***************************/
        do{
        temp=new node();
        cout<<"Enter value at the start of the node: "<<endl;
        cin>>temp->data;

        temp->next=head;

        head=temp;

        cout<<"Enter your choice: "<<endl;

        cin>>choice;
        }while(choice==1);

        temp=head;

        while(temp!=0)
        {
            cout<<temp->data<<" ";
            temp=temp->next;

        }


        /************** iNSERTION AT MIDDLE OF THE LINKLIST***********/

        node *temp2;
        int location=0;

        cout<<"\n Enter your location"<<endl;

        cin>>location;

        temp=new node();

        cout<<"\n Enter data in node: "<<endl;
        cin>>temp->data;

        temp2=head;


        while(location-1>0)

        {
            location--;
            temp2=temp2->next;
        }
        temp->next=temp2->next;
        temp2->next=temp;

        temp=head;

        while(temp!=0)
        {
            cout<<temp->data<<" ";
            temp=temp->next;
        }

    /**************************Search traverse*************/

    int value;
    int count=1;
    int flag=0;
    cout<<"\n Enter value you want to search in LinkList: "<<endl;
    cin>>value;
    temp=head;
    while(temp!=0)
    {
        if(temp->data==value)
        {
            cout<<"Data found successfully at index "<<count<<endl;
            flag=1;
            break;
        }
        else
        {
            temp=temp->next;
            count++;
        }
    }

    if(flag==0)

    {
        cout<<"Data not found"<<endl;
    }
    /**************************deleting node******************/
    int b=0;
    int item;
    node *temp3;
    cout<<"which data do you want to delete?"<<endl;
    cin>>item;
    temp=head;
    while(temp->next->next!=0)
    {
        if(temp->next->data==item)
        {
            cout<<"Data found successfully"<<endl;
            b=1;
            break;
        }
        else
        {
            temp=temp->next;
            temp3=temp->next;
        }
    }

    if(b==0)

    {
        cout<<"Data not found"<<endl;
    }
    else
    {
        temp->next=temp->next->next;
        delete temp3;
    }

    temp=head;

        while(temp!=0)
        {
            cout<<temp->data<<" ";
            temp=temp->next;
        }


    return 0;

}

Monday, 26 November 2018

Binary Search in C++



#include <iostream>
using namespace std;


void binarysearch(int arr[],int s,int size);
void binarysearch(int arr[],int s,int size)
{
    int lower=0,higher=size-1,m;
    while(lower<=higher)
    {
        m=(lower+higher)/2;
        if(s==arr[m])
        {
        cout<<"Search found at index"<<m<<endl;
        return;
        }
        else if(s>arr[m])
            lower=m+1;
        else
            higher=m-1;
    }
    cout<<"Search not found"<<endl;
}

/******************************************/

int main()
{
    int n[5],s,size;
    cout<<"Enter value in array of type int:"<<endl;
    for(int i=0;i<5;i++)
    {
     cin>>n[i];
    }
    cout<<"Enter number in Search: ";
    cin>>s;
    size=sizeof(n)/sizeof(n[0]);
    binarysearch(n,s,size);
    return 0;
}


Selection sorting Dynamically



Worst-Complexity: n ^ 2
Average-Complexity: n ^ 2
Best-Complexity: n ^ 2

Space-Complexity:  1

#include<iostream>
using namespace std;

/*********************sorting function********************/

void selection_Sort(int arr[], int n)
{
    int i, j, min;

    for (i = 0; i < n-1; i++)
    {
        min = i;
        for (j = i+1; j < n; j++)
          if (arr[j] < arr[min])
            min = j;

          swap(arr[min],arr[i]);
    }

 /****************** Printing values*****************************/

void print_Array(int arr[], int size) 

    int i; 

    for (i=0; i < size; i++) 

        cout<<arr[i];

cout<<endl; 

/**********************Driver function*************************/

int main() 

int *arr;

int n;

cout<<"How many numbers your want to sort:"<<endl;

    cin>>n;

    arr=new int[n];

    cout<<"Enter the numbers:"<<endl;

for(int i=0;i<n;i++)

{

cin>>arr[i];

}    

selection_Sort(arr, n); 

    cout<<"After sorting array: \n"<<endl; 

    print_Array(arr, n); 

    return 0;