473,763 Members | 6,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help implementing an ordered-list:storage structure is linked-list using 2arrays

1 New Member
I need help with a program. I have implemented that following header file with an unordered list using one array, but i need to be able to use an ordered list and 2 arrays (one for the links and one to use as an index to the freearray cells).
Here is the exact problem specifications:
Create an ordered list template class named OLType to implement an ordered list with operations of insert, remove, print, empty, full, size. The storage structure is to be a linked-list emulation using dynamic arrays. It will require a minimum of two arrays, one for the data and one for the 'next' links. The 'free' list can be incorporated into the 'next' links array if done correctly. The 'public' portion of your class file must be as follows:
public:
OLType(size_t n=100);
~OLType();
void insert(const T& item);
void remove(const T& item);
void print() const;
size_t size() const;
bool empty() const;
bool full() const;

Here is the code I have so far:

#ifndef OLType_H
#define OLType_H

#include <iostream>

using namespace std;

template <class T>
class OLType {
public:
OLType(size_t n=100);
~OLType();
void insert(const T& item);
void remove(const T& item);
void print() const;
size_t size() const;
bool empty() const;
bool full() const;
private:
size_t MAX_LENGTH;
size_t n; // max number that can be stored in the list
int count; // number of elements in the list
T *data; // pointer to the array that holds the list elements
};

template <class T>
OLType<T>::OLTy pe(size_t n) {
MAX_LENGTH = n;
count = 0;
data = new T[MAX_LENGTH];
}

template <class T>
OLType<T>::~OLT ype() {
delete [] data;
}

template <class T>
void OLType<T>::inse rt(const T& item) {
data[count] = item;
count++;
}

template <class T>
void OLType<T>::remo ve(const T& item) {
int i = 0;
while (i<count && item != data[i])
i++;
if (i<count) {
data[i] = data[count-1];
count--;
}
}

template <class T>
void OLType<T>::prin t() const {
int i;
for(i=0; i<count; ++i)
cout << data[i] << " ";
}

template <class T>
size_t OLType<T>::size () const {
return count;
}

template <class T>
bool OLType<T>::empt y() const {
return (count == 0);
}

template <class T>
bool OLType<T>::full () const {
return (count == MAX_LENGTH);
}

#endif

Any help with solving this problem would be greatly appreciated. I am not that strong of a programmer and just cannot seem to find the correct way to do this problem. Thank you.
Sep 12 '06 #1
1 3332
Banfa
9,065 Recognized Expert Moderator Expert
Well I personally would not normally implement a linked list as 2 arrays, I would use a single array of structures.

However it is possible.

You next step is to set up the array of "next" pointers. However rather than pointers I think these will need to be an integer type. This array will need the same number of entries as data. Assuming that this array of ints is called nextIndex then for any given current index IX

data[IX] = the value at this index
nextIndex[IX] = the next index in the list

You will need 3 other things

1. A special value (#defined or static const) indicating the end of the list

2. A data member recording the first index in the list

3. A data member recording the first index in the free list

Since any given index can only be used (exclusive) or not used (i.e. can't be used and not used then the same array of indexes can be used to hold the list of free entries. As I have stated in 3 above all you need is a new starting point.
Sep 12 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
6489
by: Kevin Altis | last post by:
Does anyone have experience running Python from a USB storage device? Whether it is the need for doing a demo of your application, doing a bit of consulting, or just showing off Python, it would be handy to be able to run Python on machines that don't already have Python installed. I'm thinking about giving this a try, but wondered if anyone is already doing it and the downsides, if any? CD-ROM is not very effective because the media is...
1
1741
by: adeleinandjeremy | last post by:
I am taking a second programming course in Java and am currently attempting to apply what I have learned using Python instead. One thing that is puzzling me is how to use an iterator. I am writing a module containing everything I'd need for canonical linked lists. One particularly useful feature would be to use a for loop over the whole structure. For this I have learned the benefits of iterators. I have read a few book entries on Python...
2
1465
by: JTrigger | last post by:
I am rather new to the XML and XSD world and was wondering what the code would look like to write the following XSD items as classes in C# with all the proper XML attributes to make them serializable. Thanks in advance. <xsd:complexType name="Order"> <xsd:sequence> <xsd:element ref="OrderHeader"/>
2
2052
by: fumanchu | last post by:
I need to insert records into a Sybase database via a linked table. I have a valid, tested DSN ODBC connection to the Sybase database named 'SBA9link'. I also have created a link to a table in the Sybase database that I need to insert into named 'dbo_External_Data'. This is the only means that I have to communicate with the Sybase database. Before I can do inserts into this table I must send the Sybase database an authentication...
10
8718
by: Duncan M Gunn | last post by:
Hi, I need to store the following matrix of values: T U V A 2 1 1 B 2 - - C - - 2 Where (-) is an empty cell.
3
1830
by: Dongsheng Ruan | last post by:
Not quite related with Python. But my Data Structure course is experiemented on python and there is no data structure group, So I have to post here: Write a procedure (in pseudocode!) to increase the number of buckets in a (closed) hash table. Analyze its time and space complexity.
1
2276
by: hmoundekar | last post by:
actually i want to generate a tree structure on client side, the application is simple web based, and need to display the data extracted from the database to client in tree structure. but the problem is that i need to display the tree of the data in tabular format, means expanding of tree should expand the table rows and collapsing of tree should collapse the table rows. if any one knows the way to do this, plz help me out. u all can mail...
1
1758
by: a Wellner | last post by:
I have a Database stored on the server, and a replica on a laptop, used for data collection in the field. The laptop is only connected to the network during synchronization. I am linking to tables in another database, maintained by another agency; the linked tables are used as the source for a lookup field. The data in the table I am linking to changes monthly. If I have the table linked I get a network error when I attempt to access the...
3
2207
by: dkultasev | last post by:
Hello, I have database, which contains the list of laptop companies and some information about them. Some laptop models, have series, sub series, family's and so on. for example. Acer Aspire 5102WLMi. Company: Acer Family: Aspire Serie: 5100 Model: 5102WLMi
2
1557
by: e2point | last post by:
i need to create a storage module which can store any thing the user wants. I want it to handle almost any storage requirement, so that clients can define their own key classes derived from the base key class which is defined by the storage module itself. for example: in the storage module we have class base_key { public:
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.