Professional Documents
Culture Documents
IGU 3rd Sem Pratical File
IGU 3rd Sem Pratical File
IGU 3rd Sem Pratical File
Ateli
Mahendragarh, Haryana
Practical File
On
Session-2023
Mrs. Name:
Roll No:
INDEX
S.No. Experiment / Topic Date Signature /
Remarks
1. Implementation of Stack Using Array in
“C”
He C Program is written for implementation of STACK using Array, the basic operations of stack are
PUSH () and POP (). PUSH function in the code is used to insert an element to the top of stack, POP
function used to remove the element from the top of stack.
#include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
int main()
{
top=-1;
printf("\n Enter the size of STACK[MAX=100]:");
scanf("%d",&n);
printf("\n\t STACK OPERATIONS USING ARRAY");
printf("\n\t--------------------------------");
printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT");
do
{
printf("\n Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:
{
printf("\n\t EXIT POINT ");
break;
}
default:
OUTPUT FROM THIS INPUT
Enter the size of STACK[MAX=100]:10
STACK OPERATIONS USING ARRAY
--------------------------------
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter the Choice:1
Enter a value to be pushed:12
98
24
12
Press Next Choice
Enter the Choice:2
24
12
Press Next Choice
Enter the Choice:4
EXIT POINT
{
printf ("\n\t Please Enter a Valid Choice(1/2/3/4)");
}
}
}
while(choice!=4);
return 0;
}
void push()
{
if(top>=n-1)
{
printf("\n\tSTACK is over flow");
}
else
{
printf(" Enter a value to be pushed:");
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void pop()
{
if(top<=-1)
{
printf("\n\t Stack is under flow");
}
else
{
printf("\n\t The popped elements is %d",stack[top]);
top--;
}
}
void display()
{
if(top>=0)
{
printf("\n The elements in STACK \n");
for(i=top; i>=0; i--)
printf("\n%d",stack[i]);
printf("\n Press Next Choice");
}
else
{
printf("\n The STACK is empty");
}
}
Output
Linked List: 10 15 20 25
Enter element to search: 20
Item found at position: 3
C Program to search an element in a linked list
There is Two methods to Search the element in list –
Method 1: Iterative
Method 2: Recursive
Method 1 (Iterative)
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
node2->data = 15;
node2->next = node3;
node3->data = 20;
node3->next = node4;
node4->data = 25;
node4->next = NULL;
if (index == -1)
printf ("Item not found");
else
printf ("Item found at position: %d", index + 1);
return 0;
}
Output
Linked List: 10 15 20 25
Enter element to search: 10
Item found at position: 1
Method 2 (Recursive)
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int main ()
{
int item;
node2->data = 15;
node2->next = node3;
node3->data = 20;
node3->next = node4;
node4->data = 25;
node4->next = NULL;
if (index == -1)
printf ("Item not found");
else
printf ("Item found at position: %d", index + 1);
return 0;
}
Output:
Enter 6 integers ::
Enter 1 integer :: 4
Enter 2 integer :: 1
Enter 3 integer :: 8
Enter 4 integer :: 6
Enter 5 integer :: 0
Enter 6 integer :: 9
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element
and the highest address to the last element.
Here is source code of the C Program to sort array in descending order using bubble sort. The C program
is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also
shown in below.
#include<stdio.h>
int main(){
int array[50], n, i, j, temp;
printf("Enter number of elements :: ");
scanf("%d", &n);
printf("\nEnter %d integers :: \n", n);
for(i = 0; i < n; i++)
{
printf("\nEnter %d integer :: ", i+1);
scanf("%d", &array[i]);
}
#include <stdio.h>
#define MAXSIZE 10
void main()
{
int array[MAXSIZE];
int i, j, num, temp;
Begin with the leftmost element of arr[] and one by one compare x with each element.
If x matches with an element then return the index.
If x does not match with any of the elements then return -1.
#include<stdio.h>
int main()
{
int a[20],i,x,n;
printf("How many elements?");
scanf("%d",&n);
for(i=0;i<n;++i)
if(a[i]==x)
break;
if(i<n)
printf("Element found at index %d",i);
else
printf("Element not found");
return 0;
}
Output
Enter A Number : 67
#include <stdio.h>
#include <conio.h>
main()
{
int arr[]={12,23,78,98,67,56,45,19,65,9},key,i,flag=0;
clrscr();
printf("\nENTER A NUMBER: ");
scanf("%d",&key);
for(i=0;i<10;i++)
{
if(key==arr[i])
flag=1;
}
if(flag==1)
printf("\nTHE NUMBER %d EXISTS IN THE ARRAY",key);
else
printf("\nTHE NUMBER %d DOES NOT EXIST IN THE ARRAY",key);
getch();
}
Output:
If the key is present:
---------------------------------------------------
(Program exited with code: 0)
Press any key to continue. . . . .
C Program to implement Binary Search
Binary Search In C:
A Binary Search is a sorting algorithm, that is used to search an element in a sorted array. A binary
search technique works only on a sorted array, so an array must be sorted to apply binary search on the
array. It is a searching technique that is better then the liner search technique as the number of
iterations decreases in the binary search.The logic behind the binary search is that there is a key. This
key holds the value to be searched. The highest and the lowest value are added and divided by 2.
Highest and lowest and the first and last element in the array. The mid value is then compared with the
key. If mid is equal to the key, then we get the output directly. Else if the key is greater then mid then
the mid+1 becomes the lowest value and the process is repeated on the shortened array. Else if the key
value is less then mid, mid-1 becomes the highest value and the process is repeated on the shortened
array. If it is not found anywhere, an error message is displayed.
Example
#include <stdio.h>
int main()
{
int i, low, high, mid, n, key, array[100];
printf("Enter number of elementsn");
scanf("%d",&n);
printf("Enter %d integersn", n);
for(i = 0; i < n; i++)
scanf("%d",&array[i]);
printf("Enter value to findn");
scanf("%d", &key);
low = 0;
high = n - 1;
mid = (low+high)/2;
while (low <= high) {
if(array[mid] < key)
low = mid + 1;
else if (array[mid] == key) {
printf("%d found at location %d.n", key, mid+1);
break;
}
else
high = mid - 1;
mid = (low + high)/2;
}
if(low > high)
printf("Not found! %d isn't present in the list.n", key);
return 0;
}
Command syntax
CREATE DATABASE
The CREATE DATABASE statement is a Data Definition Language (DDL) statement in SQL that creates a
new database. The syntax for the statement is:
Here are some things to note about the CREATE DATABASE statement:
Database names: Database names are case-sensitive on Linux or UNIX, but not on Windows.
Privileges: The user must have the CREATE privilege for the database.
Connection: If a previous CONNECT statement established an explicit connection to a database,
the user cannot use the CREATE DATABASE statement until they use the DISCONNECT statement
to close the connection.
The CREATE DATABASE command initializes a new database with an optional user-defined collating
sequence, creates the three initial table spaces, creates the system tables, and allocates the recovery log
file. When you initialize a new database, the AUTOCONFIGURE command is issued by default.
Important: The Triple Data Encryption Standard (3DES) native encryption option is deprecated and
might be removed in a future release. As a replacement, use the Advanced Encryption Standard (AES)
native encryption option.
Note: When the instance and database directories are created by the Db2® database manager, the
permissions are accurate and cannot be changed.
When the CREATE DATABASE command is issued, the Configuration Advisor also runs automatically. It
means that the database configuration parameters are automatically tuned for you according to your
system resources. In addition, Automated RUNSTATS is enabled. To disable the Configuration Advisor
from running at database creation, refer to the DB2_ENABLE_AUTOCONFIG_DEFAULT registry variable.
To disable Automated RUNSTATS, refer to the auto_runstats database configuration parameter.
Adaptive Self-Tuning Memory is also enabled by default for single partition databases. To disable
Adaptive Self-Tuning-Tuning Memory by default, refer to the self_tuning_mem database configuration
parameter. For multi-partition databases, Adaptive Self-Memory is turned off by default.
If no code set is specified on the CREATE DATABASE command, then the collations that are allowed are:
SYSTEM, IDENTITY_16BIT, language-aware-collation, and locale-sensistive-collation (SQLCODE -1083).
The default code set for a database is UTF-8. If a particular code set and territory is needed for a
database, the required code set and territory can be specified in the CREATE DATABASE command.
Scope
In a partitioned database environment, this command affects all database partitions that are listed in
the db2nodes.cfg file.The database partition from which this command is issued becomes the catalog
database partition for the new database.
Command syntax
Authorization
You must have one of the following authorities:
SYSADM
SYSCTRL
Required connection
Instance. To create a database at another (remote) database partition server, you must first attach to
that server. A database connection is temporarily established by this command during processing.
Syntax 1
The syntax for the CREATE TABLE AS statement when copying all of the columns in SQL is:
Example 1.1
Let's look at an example that shows how to create a table by copying all columns from another table.
AS (SELECT *
FROM companies
Syntax 2
The syntax for the CREATE TABLE AS statement copying the selected columns is:
FROM old_table);
Example 2.1
Let's look at an example that shows how to create a table by copying selected columns from another
table.
FROM companies
WHERE id > 1000);
Description
You can also use the SQL CREATE TABLE AS statement to create a table from an existing table by copying
the existing table's columns.
It is important to note that when creating a table in this way, the new table will be populated with the
records from the existing table (based on the SELECT Statement). Just like Syntax
If there were records in the companies table, then the new suppliers table would also contain the
records selected by the SELECT statement. For Example 1.1
Example
Let's look at an example that shows how to create a table by copying selected columns from multiple
tables.
Syntax
Alter Table:-
ALTER TABLE
Use the ALTER TABLE statement to alter the definition of a nonpartitioned table, a partitioned table, a
table partition, or a table subpartition. For object tables or relational tables with object columns, use
ALTER TABLE to convert the table to the latest definition of its referenced type after the type has been
altered.
Note: Oracle recommends that you use the ALTER MATERIALIZED VIEW LOG statement, rather than
ALTER TABLE, whenever possible for operations on materialized view log tables.
Prerequisites
The table must be in your own schema, or you must have ALTER object privilege on the table, or you
must have ALTER ANY TABLE system privilege.
If you are not the owner of the table, then you need the DROP ANY TABLE privilege in order to use the
drop_table_partition or truncate_table_partition clause.
You must also have space quota in the tablespace in which space is to be acquired in order to use the
add_table_partition, modify_table_partition, move_table_partition, and split_table_partition clauses.
When a partitioning operation cascades to reference-partitioned child tables, privileges are not required
on the reference-partitioned child tables.
When using the exchange_partition_subpart clause, if the table data being exchanged contains an
identity column and you are not the owner of both tables involved in the exchange, then you must have
the ALTER ANY SEQUENCE system privilege.
To enable a unique or primary key constraint, you must have the privileges necessary to create an index
on the table. You need these privileges because Oracle Database creates an index on the columns of the
unique or primary key in the schema containing the table. To enable or disable triggers, the triggers
must be in your schema or you must have the ALTER ANY TRIGGER system privilege.
To use an object type in a column definition when modifying a table, either that object must belong to
the same schema as the table being altered, or you must have either the EXECUTE ANY TYPE system
privilege or the EXECUTE object privilege for the object type.
Additional Prerequisites for Flashback Data Archive Operations
To use the flashback_archive_clause to enable historical tracking for the table, you must have the
FLASHBACK ARCHIVE object privilege on the flashback archive that will contain the historical data. To
use the flashback_archive_clause to disable historical tracking for the table, you must have the
FLASHBACK ARCHIVE ADMINSTER system privilege or you must be logged in as SYSDBA.
For information about database backup operations between different operating systems and hardware
platforms, see “Backup and restore operations between different operating systems and hardware
platforms”.
Scope
In a partitioned database environment, if no database partitions are specified, this command affects
only the database partition on which it is run.
If the option to perform a partitioned backup is specified, the command can be called only on the
catalog database partition. If the option specifies that all database partition servers are to be backed up,
it affects all database partition servers that are listed in the db2nodes.cfg file. Otherwise, it affects the
database partition servers that are specified on the command.
Authorization
SYSADM
SYSCTRL
SYSMAINT
Required connection
Database. This command automatically establishes an exclusive connection to the specified database.
Note: If a connection to the specified database exists, that connection is terminated and a new
connection established specifically for the backup operation. The connection is stopped at the
completion of the backup operation.