Monday, January 6, 2025

Linked List Implementation using C++ Structure

3 Nodes Linked List Implementaion


Single Linked list

#include<iostream>
using namespace std; 

struct Node{

int data;

Node* next;


Node(int value){

data = value;

next = nullptr;

}

};

int main(){

Node* node1 = new Node(10);

Node* node2 = new Node(20);

Node* node3 = new Node(30);

 

Node* head = node1;

node1->next = node2;

node2->next = node3;


Node* current = head;

while(current != nullptr){

    cout<<current->data << "->";

    current = current->next;

}

cout<<"nullptr";

return 0;

}

_________________________________


Circular Linked list

#include<iostream>
using namespace std;
struct Node{

int data;
Node* next;

Node(int value){
data = value;
next = nullptr;
}

};

int main(){
 // crate nodes
    Node* node1 = new Node(10);
    Node* node2 = new Node(20);
    Node* node3 = new Node(30);

//connection
Node* head = node1;
node1->next =node2;
node2->next = node3;
node3->next = head; // make it circular

//Traversing
Node* p = head;
do{
    cout<<p->data<<"->";
    p = p->next;
}while(p != head);
cout<<"(head)";

return 0;

}
_______________________________________

Double Linked list 

#include<iostream>
using namespace std;
struct Node{

int data;
Node* next;
Node* prev; // DLL

Node(int value){
data = value;
next = nullptr;
prev = nullptr; //DLL
}

};

int main(){
 // crate nodes
    Node* node1 = new Node(10);
    Node* node2 = new Node(20);
    Node* node3 = new Node(30);

//connection
Node* head = node1;

node1->next =node2;
//node1->prev =nullptr;

node2->next = node3;
node2->prev =node1;

//node3->next = nullptr;
node3->prev =node2;

//Traversing
Node* p = head;
while(p != nullptr){
    cout<<p->data<<"->";
    p = p->next;
}
cout<<"nullptr";

return 0;

}

________________________________________________





Saturday, July 29, 2023

Python Pandas Library

 Pandas

  • Pandas is a Python library used for working with data sets.
  • It has functions for analyzing, cleaning, exploring, manipulating data, and plotting data.
  • The name "Pandas" has a reference to both "Panel Data" and "Python Data Analysis" and was created by Wes McKinney in 2008.


Main Features

  1. Explorin Data
  2. Preprocessing / Cleaning Data 
  3. Analyzing Data 
  4. Visualization of Data

Coding Editor

  • Jupyter
  • Google Colab

Pandas Installaltion

pip install pandas
import pandas as pd

Exploring Data

1. Reading Data Frame
df = pd.read_csv('sinovac.csv')

2. head() and tail() function
 The head function will display the first rows, and the tail will be the last rows. 
By default, it shows 5 rows.

3. info()
To display data frames information we can use info() the method.

4. Display the number of rows and columns.
df.shape

5. Display column names
df. columns

6. display one column only
df['col name'].head(3)

7. display multiple  columns
df[['Age', 'Transaction_date', 'Gender']].head(4)


Data Cleaning

1. Delete Columns name
df.drop(['Transaction_ID'], axis=1, inplace=True)

2. Change the Columns name
df. rename(columns={"Transaction_date": "Date", "Gender": "Sex"},
inplace=True)

3.  Remove duplicate
# Display duplicated entries 
df. duplicated().sum()
# dropping ALL duplicate values
df.drop_duplicates(inplace = True)

4. Display missing values information
df.isna().sum().sort_values(ascending=False)
#Delete Nan rows of Job Columns
df.dropna(inplace=True)


Data Analysis

1. df. describe()
 This function will display most of the basic statistical measurements. 

2. df['State_names'].unique()
 Shows all unique values 

3.  df['Gender'].value_counts()
Counts of unique values
# Calculate the percentage of each category
df['Gender'].value_counts(normalize=True)
df['State_names'].value_counts().sort_values(ascending = False).head(20)

4. Sort Values by State_names
df.sort_values(by=['State_names']).head(3)
# Sort Values Amount_spent with descending order
df.sort_values(by=['Amount_spent'], ascending=False).head(3)

5.  nlargest() and nsmallest() functions
We can use nlargest() and nsmallest() functions for displaying largest and smallest values with desired numbers.
df.nlargest(4, 'Amount_spent').head(10)
df.nsmallest(3, 'Age').head(10) 

#6. filtering - Only show Paypal users
condition = df['Payment_method'] == 'PayPal'
df[condition].head(4)


Data Visualization

1 . Line plot
# use plot() method on the data frame
df.plot('year', 'price');


2. Bar plot
df['Employees_status'].value_counts().plot(kind='bar');
For vertical bar:
df['Employees_status'].value_counts().plot(kind='barh');

3 Pie plot
df['Segment'].value_counts().plot( kind='pie');








Monday, July 24, 2023

Lists in Python

 1. List

  • A list is a collection that is ordered and changeable. Allows duplicate members.
  • Python Lists are similar to arrays in C.
  •  However, the list can contain data of different types. 
  • The items stored in the list are separated with a comma (,) and enclosed within square brackets [].


 

Examples

list = ["apple", "banana", "cherry"]    #list of fruits
print(list)
 list = ["apple", "banana", "cherry", "apple", "cherry"]     #duplicate items
print(list)
 print(len(list))     #len()...length of list
list1 = ["abc", 34, True, 40, "male"]   #list of diff data types
mylist = ["apple", "banana", "cherry"]
print(type(mylist))    #type of list

2. Python - Access List Items

List items are indexed and you can access them by referring to the index number
The first item has index 0.

thislist = ["apple", "banana", "cherry"]
print(thislist[1])  

3. Negative indexing means start from the end
-1 refers to the last item, -2 refers to the second last item etc.

list = ["apple", "banana", "cherry"]
print(list[-1])

4. Range of Indexes
You can specify a range of indexes by specifying where to start and where to end the range.
thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
print(thislist[2:5])
Note: The search will start at index 2 (included) and end at index 5 (not included).

5. Python - Change List Items

To change the value of a specific item, refer to the index number:
thislist = ["apple", "banana", "cherry"]
thislist[1] = "blackcurrant"
print(thislist)

thislist = ["apple", "banana", "cherry", "orange", "kiwi", "mango"]
thislist[1:3] = ["blackcurrant", "watermelon"]
print(thislist)

6. Python - Add List Items

To add an item to the end of the list, use the append() method

a = ["apple", "banana", "cherry"]
a.append("orange")
print(a)

7. Python - Remove List Items

The remove() method removes the specified item.
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
The pop() method removes the specified index.
thislist = ["apple", "banana", "cherry"]
thislist.pop(1)
print(thislist)
The del keyword also removes the specified index
thislist = ["apple", "banana", "cherry"]
del thislist[0]
print(thislist)

8. Python - Clear the List

The clear() method empties the list.
The list still remains, but it has no content.

thislist = ["apple", "banana", "cherry"]
thislist.clear()
print(thislist)



Saturday, July 22, 2023

Python Basic Concepts Coding

Python 

Python is the most popular high-level language in 2023, mostly used for data science and machine learning.


 






1. Syntax (Output)

print("welcome")

2. Comments

Single line 

#first line comment

Multi line 

#multiple line comments

#first line comment

#second line comment

#third line comment

3. Variables

x = 10   

y = 10.5  

z = "welcome"  

print(x, y, z)

4. Arithmetic Operators

x = 9

y = 4

print (x+y)

5. Conditions

x = 15

if x >10:
    print("passed")
    print("passed")
    print("passed")
    print("passed")

else:
    print("failed")
    
    
print("out of if-else")
_______________________________________________

#Conditions/nested if-else(multiple conditions)

x = 100

if x <90:
    print("excelent")
    
elif x < 80:
    print("weldone")
    
elif x < 70:
    print("nice")
else:
    print("good")
    
    
print("out of if-else") #out of else-if

6. loops (while, for)


x = 1
while x < 5:
    print("Paksitan")
    x = x + 1   #x++

7. functions (code reusability)

def show(x ,y ):

    print(x+y)

show(5, 6)

show(3, 4)

show(8, 8)

8. OOP(obj, class, inheritance)

class A:

    x = 10

    y = 20

    def show(self):

        print (self.x) 

        print (self.y) 

        

ob = A()  #obj creation

ob.show()

9. Single Inheritance

class A:
    def showA(self):
        print("parent class A")

obj = A()

obj.showA()

10. Multiple Inheritance

class A:
    def showA(self):
        print("parent class A")

class B:
    def showB(self):
        print ("parnt B")
        
class C(A, B):
    def showC(self):
        print ("chidl C")

obj = C()

obj.showA()
obj.showB()
obj.showC()



        



Wednesday, July 12, 2023

Stateless Widget VS StateFull Widget

SLW VS SFW







StateLessWidget

  • SLW widgets are static widgets and don't change (properties or data) during lifetime
  • SLW used to display on UI
  • use SLW subclass
  • Examples screen only show UI 
  • (Text, Icon, Image, Container)

StateFull Widget

SFW are dynamic widgets and change during the lifetime

STW have an internal state

STW is used for data change

use SFW subclass + setstate ()

Examples Screen with data (variable) change 

(TextField, Radion button, Checkbox button 

SFW Example(Checkbox)


SFW Example(TextField)



Coding Example (SLW)


// stateless widget
import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(MaterialApp(
    home: counter(), //calling SLW
  ));
}

//outside main()
class counter extends StatelessWidget {
  const counter({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.amber,
      appBar: AppBar(
        backgroundColor: Colors.black,
        title: const Text(
          "Counter",
          style: TextStyle(fontSize: 20),
        ),
        centerTitle: true,
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            Center(
              child: Text( // Statless widget
                "welcome to Flutter",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
            )
          ],
        ),
      ),
    );
  }
}

SateFull Widget 




// statefull widget
import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(MaterialApp(
    home: calculator(), //calling SFW
  ));
}

//outside main()

class calculator extends StatefulWidget { // SFW class
  const calculator({super.key});

  @override
  State<calculator> createState() => _calculatorState();
}

class _calculatorState extends State<calculator> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Center(
            child: Text(
              "we are using StateFull Widget",
              style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            ),
          )
        ],
      ),
    );
  }
}







Tuesday, July 11, 2023

FloatingAction Buttion in Flutter

 FluttingAction Buttion

 It is a rounded shape widget that floats on the screen.









Properites

  • child
  • tooltip
  • foregroundColor
  • backgroundColor
  • hoverColor
  • splashColor
  • elevation

Coding Example

import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(MaterialApp(
    home: Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: FloatingActionButton(
            child: Text(
              "Ok",
              style: TextStyle(fontSize: 19),
            ),
            tooltip: "Add buttion",
            elevation: 50,
            backgroundColor: Colors.red,
            foregroundColor: Colors.black,
            hoverColor: Colors.amber,
            splashColor: Colors.white,
            onPressed: () {}),
      ),
    ),
  ));
}




Monday, July 10, 2023

Profile App in Flutter

 Profile APP

Profile App provides basic personal information about a person.









Coding Example (Flutter)





import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
        backgroundColor: const Color.fromARGB(255, 164, 69, 69),
        body: Padding(
          padding: const EdgeInsets.all(100.0),
          child: Center(
            child: Column(
              children: [
                Image.network(
                  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQDKFmIAeGGdc5Sudv7nTDy6S1_fhcJ8lvlHw&usqp=CAU",
                  height: 100,
                  width: 100,
                ),
                const SizedBox(
                  height: 20,
                ),
                const Text(
                  "Muhammad Arsalan",
                  style:
                      TextStyle(fontWeight: FontWeight.bold, color: Colors.red),
                ),
                const Text(
                  "Professor of Mathematics",
                  style: TextStyle(fontSize: 10, color: Colors.grey),
                ),
                const SizedBox(
                  height: 10,
                ),
                const Divider(
                  color: Colors.red,
                  thickness: 3,
                ),
                const SizedBox(
                  height: 10,
                ),
                Container(
                    padding: const EdgeInsets.only(left: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(
                          // color: Colors.white,
                          ),
                    ),
                    child: const Row(
                      children: [
                        Icon(
                          Icons.mail,
                          color: Colors.red,
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Text("arsalan22@gmail.com",
                            style: TextStyle(
                              color: Colors.grey,
                              fontWeight: FontWeight.bold,
                            )),
                      ],
                    )),
                const SizedBox(
                  height: 20,
                ),
                Container(
                    padding: const EdgeInsets.only(left: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(
                          // color: Colors.white,
                          ),
                    ),
                    child: const Row(
                      children: [
                        Icon(
                          Icons.call,
                          color: Colors.red,
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Text("0311-7687654",
                            style: TextStyle(
                              color: Colors.grey,
                              fontWeight: FontWeight.bold,
                            )),
                      ],
                    )),
                const SizedBox(
                  height: 20,
                ),
                Container(
                    padding: const EdgeInsets.only(left: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(
                          // color: Colors.white,
                          ),
                    ),
                    child: const Row(
                      children: [
                        Icon(
                          Icons.home,
                          color: Colors.red,
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Text("Swabi",
                            style: TextStyle(
                              color: Colors.grey,
                              fontWeight: FontWeight.bold,
                            )),
                      ],
                    )),
                const SizedBox(
                  height: 20,
                ),
                Container(
                    padding: const EdgeInsets.only(left: 10),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10),
                      border: Border.all(
                          // color: Colors.white,
                          ),
                    ),
                    child: const Row(
                      children: [
                        Icon(
                          Icons.logout,
                          color: Colors.red,
                        ),
                        SizedBox(
                          width: 5,
                        ),
                        Text("Logout",
                            style: TextStyle(
                              color: Colors.grey,
                              fontWeight: FontWeight.bold,
                            )),
                      ],
                    )),
                const SizedBox(
                  height: 40,
                ),
                Row(
                  children: [
                    Container(
                        height: 30,
                        width: 200,
                        decoration: BoxDecoration(
                          color: Colors.amber,
                          borderRadius: BorderRadius.circular(15),
                        ),
                        child: const Padding(
                          padding: EdgeInsets.only(left: 30),
                          child: Row(
                            children: [
                              Center(child: Icon(Icons.edit)),
                              SizedBox(
                                width: 10,
                              ),
                              Center(
                                child: Text(
                                  "Edit Profile",
                                  style: TextStyle(fontWeight: FontWeight.bold),
                                ),
                              )
                            ],
                          ),
                        ))
                  ],
                )
              ],
            ),
          ),
        )),
  ));
}




Linked List Implementation using C++ Structure

3 Nodes Linked List Implementaion Single Linked list #include<iostream> using namespace std;   struct Node{ int data; Node* next; Node...