DS Lab 2 Tasks
DS Lab 2 Tasks
BCS 173083
DS Lab 2 – S6
24/09/2018
#include <iostream>
class array{
private:
int size;
public:
array(){
item[i]=0;
size=0;
insert(){
if (size < 20 ){
int num;
size++;
remove(){
int del_index;
item[del_index]=item[del_index+1];
del_index++;
item[size]=0;
size--;
show(){
};
int main(){
int menu;
array a1;
do{
if (menu == 1 ){
a1.insert();
a1.show();
if (menu ==2 ){
a1.remove();
a1.show();
}while(menu != 3 );
return 0;
7.1
#include <iostream>
class List{
int *elements;
int size;
int length;
public:
////////////////////////////////// Constructor
List(int maxsize)
size=maxsize;
elements=new int[size];
length=0;
/////////////////////////////////// Destructor
~List ()
delete []elements;
void showStructure ()
if(!isEmpty())
for(int i=0;i<length;i++)
cout<<"Element:"<<elements[i]<<endl;
else
}
////////////////////////////////// List manipulation operations
if(!isFull())
elements[length]=newDataItem;
length++;
else
int remove ()
if(!isEmpty())
length--;
return elements[length];
else
//Result: Removes the data item present at the position from a list and replace the number
requested by user at its position.
if(length<position)
else
bool opt;
if(!isEmpty())
for(int i=0;i<length;i++)
if ( elements[i] == searchDataItem )
opt = 1;
if (opt) return 1;
}
/////////////////////////////////////// List status operations
bool isEmpty ()
if (length==0) return 1;
else
return 0;
bool isFull ()
else
return 0;
};
int main(){
List listobj(3);
listobj.insert(20);
listobj.showStructure();
listobj.find(2);
return 0;
7.2
#include <iostream>
class item {
private:
int list[20];
int size;
public:
item() {
list[i] = 0;
size = 0;
void insert() {
int num;
list[size] = num;
size++;
}
}
void remove() {
list[size] = 0;
size--;
void insert_at_index() {
else
cout << "Enter value at index " << in_index << endl;
list[in_index + 1] = temp1;
temp1 = temp2;
in_index++;
}
size++;
void remove_at_index() {
int del_index;
del_index++;
list[size] = 0;
size--;
void show() {
void length() {
cout << "current Length of list: " << size << endl;
};
void main() {
item a1;
int menu;
do {
cout << " 3 to Insert value at specific index \n 4 to delete value from specific index \n";
cout << " 5 to get length of list \n 6 to display current values in list \n 7 to exit menu\n";
if (menu == 1) {
a1.insert();
a1.show();
if (menu == 2) {
a1.remove();
a1.show();
if (menu == 3) {
a1.insert_at_index();
a1.show();
if (menu == 4) {
a1.remove_at_index();
a1.show();
if (menu == 5)
a1.length();
if (menu == 6)
a1.show();
system("Pause");