Answer to Question #239884 in C++ for Python

Question #239884
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.
1
Expert's answer
2021-09-21T02:12:44-0400
#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;
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS