implement a list data structure including following operations using array adt .
get() update() length() back() next() start() end() remove() add() .
Note: implement above operations only using pointers without using any indexes of arrays.
#include<iostream>
using namespace std;
int arr[10], index;
void Add(){
cout<<"Enter the elements of the list\n";
for(int i=0; i<10; i++){
cin>>arr[i];
index++;
}
}
int length(){
return index;
}
int back(){
return arr[index-1];
}
int start(){
return arr[0];
}
int Next(int data){
int item;
for(int i=0; i<10; i++){
if(arr[i]==data){
item = arr[i+1];
}
}
return item;
}
int end(){
return arr[9];
}
void Remove(int data){
for(int i=0; i<10; i++){
if(arr[i]==data){
arr[i] == 0;
}
}
}
void get(int data){
for(int i=0; i<10; i++){
if(arr[i]==data){
cout<<"Index: "<<i<<endl;
}
}
}
void update(int data, int item){
for(int i=0; i<10; i++){
if(arr[i]==data){
arr[i] = item;
}
}
}
Comments
Leave a comment