<file_sep># DSFile

Data Structures file

Bhavika
(1610991225)
<file_sep>#include<iostream>
using namespace std;

void del_val(int arr[], int size)
	{
		int del, i, count=0;
		cout<<"Enter element to be deleted: ";
		cin>>del;
		for(i=0; i<size; i++)
		{
			if(arr[i]==del)
			{
				for(int j=i; j<(size-1); j++)
				{
					arr[j]=arr[j+1];
				}
				count++;
				break;
			}
		}
		if(count==0)
		{
			cout<<"Element not found";
		}	
		else
		{
			cout<<"New array:\n";
			for(i=0; i<(size-1); i++)
			{
				cout<<arr[i]<<" ";
			}
		}
	}
void del_pos(int a[], int size)
{
	int pos;
	cout<<"Enter position of element to be deleted:";
	cin>>pos;
	if(pos>size)
	{
		cout<<"Value is out of range";
	}
	else
	{
		--pos;
		for(int i=pos; i<=size; i++)
		{
			a[i]=a[i+1];
		}
		cout<<"New Array:\n";
		for(int i=0; i<size-1; i++)
		{
			cout<<a[i]<<" ";
		}
	}
}

int main()
{
	int arr[50], size, i, del, count=0, opt=0;
	cout<<"Enter array size : ";
	cin>>size;
	cout<<"Enter array elements : ";
	for(i=0; i<size; i++)
	{
		cin>>arr[i];
	}
	cout<<"Enter 1 for delete by position and 2 for delete by value";
	cin>>opt;
	if(opt==1)
	{
	del_pos(arr, size);
	}
	else
	{
	del_val(arr, size);
	}
}


<file_sep>#include<iostream>
using namespace std;

int main()
{
	int arr[50], n;
	cout<<"Enter array size: ";
	cin>>n;
	cout<<"Enter elements: ";
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
	}
	cout<<"The Elements in the Array are : \n";
	for(int i=0; i<n; i++)
	{
		cout<<arr[i]<<" ";
	}
}
<file_sep>#include<iostream>
using namespace std;
int main()
{
int array[40],size,list,middle,found,first,last,i,j,temp;
cout<<"Enter size";
cin>>size;
for(i=0; i<size; i++)
{
cin>>array[i];
} 
for(i=0 ; i<size-1; i++)
{
for(j=i+1; j<size; j++)
{
if(array[i]>array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
cout<<"Enter element to be searched: ";
cin>>found;
first = 0;
	last = size-1;
	middle = (first+last)/2;
	while (first <= last)
	{
		if(array[middle] < found)
		{
			first = middle + 1;

		}
		else if(array[middle] == found)
		{
			cout<<found<<" found \n";
			break;
		}
		else
		{
			 last = middle - 1;
		}
		middle = (first + last)/2;
	}
	if(first > last)
	{
		cout<<"Not found! "<<found<<" is not present in the list.";
	}
}

