Answer to Question #242227 in C++ for john

Question #242227

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-27T01:19:06-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