Data Structure Assignment
Data Structure Assignment
CSC-221
Sir Noman
Assignment 1
NAME::Irfan Haider
CLASS: BCE-4
ENROLLMENT NO: 01-132182-035
DEPARTMENT OF COMPUTER ENGINEERING
BAHRIA UNIVERSITY | ISLAMABAD CAMPUS
Header file
#pragma once
#define ARRAYLIST_H
template <class T>
class arraylist
{
private:
T* data;
int arrlength;
int listsize;
void resize();
bool needtoresize();
public:
//constructor
arraylist();
{
//get an array set up
data = new T[10];
// initilize parameter
arrlength = 10;
listsize = 0;
}
//accessor
bool contains(T items);
int indexof(T items);
int lastindexof(T items);
T get(int index);
int size;
//modifer
void add(T item);
void add(int index, T item);
void set(int index, T item);
void remove(int index);
void remove(T item);
};
Resource file
#ifndef ARRAYLIST_H
//#include"arraylist.h"
#endif
#include "Header.h"
}
template <class T>
void arraylist<T>::add(T item)
{
// add item to the end of list
if (needtoresize())
resize();
data[listsize] = item;
listsize++;
}
// 0 1 2 3 4
// 8 3 2
// insert 3 in location 1
// 0 1 2 3 4
// 8 3 3 2
data[index] = item;
listsize++;
}
// remove
template <class T>
void arratlist<T>::remove(int index)
{
for (int i = index; i < listsize; i++)
data[i] = data[i + 1];
listsize--;
}
template <class T>
T arraylist<T>::get(int index)
{
if (index>=0 && index <= listsize)
return data[index];
// else
return 0;
}
if (item == data[i])
return i;
// did not find return
return -1;
}
if (item == data[i])
return i;
// did not find return
return -1;
}
#include"Header.h"
#include <iostream>
using namespace std;
int main() {
// Array creation
int myarray[10];
int dataarray[10];
int size;
cout << "Enter 10 integers in any order: " << endl;
for (int i = 0; i < 10; i++) {
cin >> myarray[i];
cin >> dataarray[i];
}
cout << " Data Added" << endl;
for (int i = 0; i < 10; i++) {
cout << myarray[i] << " ";
}
// Menu
int choice;
cout << "\n\n1. for Add Data.\n2. for Delete data.\n3. for update.\n4. search
data\n5. for print \n\nEnter your Choice :";
cin >> choice;
switch (choice)
{
//cases....
case 1:
{
void add(int index);
break;
}
case 2:
{
void remove(int index);
break;
}
case 3:
{
void set(int index);
break;
}
case 4:
{
void get(int index);
break;
}
case 5:
{
void print(int index);
break;
}
default:
break;
}
return 0;
}
Conclusion
By doing this assignment with full effort and hard work I have learnt how to
create three file structure and the another thing are I learnt how to create the
classes and the third things is to create the Dynamic array and the forth things is
how to Add, delete, update, find, data in the Array. And the fifth things are to
create the MENU bar Program.