SlideShare a Scribd company logo
1 of 12
When we first examined the array based and node based
implementations of the List ADT, there was one difference in
the interface: The array based version had a capacity parameter
in the CreateList function. This parameter was used to
determine the fixed maximum capacity of the List. In this
exercise, you will revise the pseudocode for the Array based
ADT to remove the fixed capacity limit. Only one of the List
operations should have a change to its header: Creating an
array-based List should now take zero parameters, and should
initially create an array based List with a capacity of 1 element.
All other operations should have unchanged headers In each of
the insert operations, instead of returning false when the array
is full, the algorithm should attempt to "grow" the capacity of
the list, and then insert. To reduce the workload of this
assignment, you only need to provide revised pseudocode for
insertTail, not the other insert operations. The other operations
would be modified in the same way. a new growList operation
will be needed to increase the capacity of the list. This
operation will be used by insertTail. If we were completely
revising the array based List ADT, we would also use this grow
operation in insertHead, and insertAfter. The grow operation
should: o should now take zero parameters, and should initally
create an array based ist with a capacity o o 1. 2. allocate a new
larger array copy the contents of the old array into the new
array
Solution
#include<stdio.h>
#include<alloc.h>
#include<conio.h>
struct list
{
int capacity;
int size;
int *array;
};
typedef struct list *ptrToNode;
typedef ptrToNode LIST;
typedef int POSITION;
int Isempty(LIST L)
{
return L->size==0;
}
void MakeEmpty(LIST L)
{
if(Isempty(L))
printf(" LIST is already Empty");
else
{
L->size=0;
printf(" Now List becomes Empty");
}
}
LIST Createlist(int max)
{
LIST L;
L=(struct list*)malloc(sizeof(struct list));
if(L==NULL)
printf(" Fatal Error");
else
{
L->capacity=max;
L->array=(int*)malloc(sizeof(int)*max);
if(L->array==NULL)
printf(" Fatal Error");
else
{
L->size=0;
printf(" List is Created successfully");
}
}
return L;
}
int Isfull(LIST L)
{
return L->size==L->capacity;
}
void Insert(int x,LIST L,POSITION P)
{
int i;
if(Isfull(L))
printf(" List is Full");
else
{
for(i=L->size-1;i>=P;i--)
L->array[i+1]=L->array[i];
L->size++;
L->array[P]=x;
}
}
POSITION Findprevious(int x,LIST L)
{
POSITION P;
P=-1;
while(P!=L->size&&L->array[P+1]!=x)
{
P++;
}
return P;
}
POSITION Find(int x,LIST L)
{
POSITION P;
P=0;
while(P!=L->size&&L->array[P]!=x)
{
P++;
}
return P;
}
void Delete(int x,LIST L)
{
int i;
POSITION P;
P=Find(x,L);
if(P==L->size)
printf(" Element not found in the list");
else
{
for(i=P;i<L->size;i++)
L->array[i]=L->array[i+1];
L->size--;
}
}
LIST Deletelist(LIST L)
{
MakeEmpty(L);
free(L);
L=NULL;
return L;
}
void Display(LIST L)
{
int i;
for(i=0;i<L->size;i++)
printf(" %d",L->array[i]);
}
“Larray.c” File:
#include"Larray.h"
#include<stdlib.h>
void main()
{
LIST L=NULL;
POSITION P;
int a,choice,ch,element;
clrscr();
printf("  1.Create 2.Insert 3.Delete 4.Display
5.MakeEmpty 6.Find 7.IsEmpty 8.IsFull 9.Deletelist
10.Exit ");
A:
printf(" Enter Ur Option:t");
scanf("%d",&choice);
switch(choice)
{
case 1:
if(L==NULL)
L=Createlist(5);
else
printf(" List is already created");
break;
case 2:
if(L==NULL)
printf(" List is not yet created");
else
{
printf(" Enter the Element to insert:t");
scanf("%d",&element);
if(L->size==0)
Insert(element,L,0);
else
{
printf(" where u want to
insert?t1:Frontt2:Backt3:middlet::: ");
scanf("%d",&ch);
if(ch==1)
Insert(element,L,0);
else
if(ch==2)
Insert(element,L,L->size);
else
if(ch==3)
{
printf(" Where you want to insert:t");
scanf("%d",&a);
P=Find(a,L);
if(P<L->size)
Insert(element,L,P);
else
printf(" Element is not in the list");
}
else
printf(" Ur choice is not available");
}
}
break;
case 3:
if(L==NULL)
printf(" List is not yet created");
if(Isempty(L))
printf(" List is empty");
else
{
printf(" Enter the element to delete:t");
scanf("%d",&a);
Delete(a,L);
}
break;
case 4:
if(L==NULL)
printf(" List is not yet created");
else
if(Isempty(L))
printf(" List is empty");
else
{
printf(" Elements present in the list are:");
Display(L);
}
break;
case 5:
if(L==NULL)
printf(" List is not yet created ");
else
MakeEmpty(L);
break;
case 6:
if(L==NULL)
printf(" Not yet created");
else
if(Isempty(L))
printf(" List is empty");
else
{
printf(" which element is to find:t");
scanf("%d",&a);
P=Find(a,L);
printf(" Element is at %dt[0 to 4 means present]t[5
means not present]",P);
}
break;
case 7:
if(L==NULL)
printf(" Not yet created");
else
if(Isempty(L))
printf(" List is empty");
else
printf(" List is not empty");
break;
case 8:
if(L==NULL)
printf(" Not yet created");
else
if(Isfull(L))
printf(" List is FULL");
else
printf(" List is not FULL");
break;
case 9:
if(L==NULL)
printf(" Not yet created");
else
{
L=Deletelist(L);
printf(" List is Deleted");
}
break;
case 10:
exit (0);
break;
default:
printf("  *******WRONG ENTRY*******");
break;
}
goto A;
}

More Related Content

Similar to When we first examined the array based and node based implementations.docx

There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
farankureshi
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
mayorothenguyenhob69
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
support58
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
arracollection
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
arpaqindia
 
Write a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdfWrite a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdf
footworld1
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
pallavi953613
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
Terry Yoast
 

Similar to When we first examined the array based and node based implementations.docx (20)

Mysql
MysqlMysql
Mysql
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
C++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docxC++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docx
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
 
BackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdfBackgroundIn many applications, the composition of a collection o.pdf
BackgroundIn many applications, the composition of a collection o.pdf
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)Java 1.5 - whats new and modern patterns (2007)
Java 1.5 - whats new and modern patterns (2007)
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Write a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdfWrite a class ArrayList that represents an array of integers. Init.pdf
Write a class ArrayList that represents an array of integers. Init.pdf
 
List,Stacks and Queues.pptx
List,Stacks and Queues.pptxList,Stacks and Queues.pptx
List,Stacks and Queues.pptx
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdfC++ Program It is only 1 rotation. Up-rotation of a stack.  Write a.pdf
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Data Structure In C#
Data Structure In C#Data Structure In C#
Data Structure In C#
 

More from ajoy21

Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
ajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
ajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
ajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
ajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

When we first examined the array based and node based implementations.docx

  • 1. When we first examined the array based and node based implementations of the List ADT, there was one difference in the interface: The array based version had a capacity parameter in the CreateList function. This parameter was used to determine the fixed maximum capacity of the List. In this exercise, you will revise the pseudocode for the Array based ADT to remove the fixed capacity limit. Only one of the List operations should have a change to its header: Creating an array-based List should now take zero parameters, and should initially create an array based List with a capacity of 1 element. All other operations should have unchanged headers In each of the insert operations, instead of returning false when the array is full, the algorithm should attempt to "grow" the capacity of the list, and then insert. To reduce the workload of this assignment, you only need to provide revised pseudocode for insertTail, not the other insert operations. The other operations would be modified in the same way. a new growList operation will be needed to increase the capacity of the list. This operation will be used by insertTail. If we were completely revising the array based List ADT, we would also use this grow operation in insertHead, and insertAfter. The grow operation should: o should now take zero parameters, and should initally create an array based ist with a capacity o o 1. 2. allocate a new larger array copy the contents of the old array into the new array Solution #include<stdio.h> #include<alloc.h>
  • 2. #include<conio.h> struct list { int capacity; int size; int *array; }; typedef struct list *ptrToNode; typedef ptrToNode LIST; typedef int POSITION; int Isempty(LIST L) { return L->size==0; } void MakeEmpty(LIST L) { if(Isempty(L)) printf(" LIST is already Empty"); else { L->size=0; printf(" Now List becomes Empty"); }
  • 3. } LIST Createlist(int max) { LIST L; L=(struct list*)malloc(sizeof(struct list)); if(L==NULL) printf(" Fatal Error"); else { L->capacity=max; L->array=(int*)malloc(sizeof(int)*max); if(L->array==NULL) printf(" Fatal Error"); else { L->size=0; printf(" List is Created successfully"); } } return L; } int Isfull(LIST L) {
  • 4. return L->size==L->capacity; } void Insert(int x,LIST L,POSITION P) { int i; if(Isfull(L)) printf(" List is Full"); else { for(i=L->size-1;i>=P;i--) L->array[i+1]=L->array[i]; L->size++; L->array[P]=x; } } POSITION Findprevious(int x,LIST L) { POSITION P; P=-1; while(P!=L->size&&L->array[P+1]!=x) { P++; }
  • 5. return P; } POSITION Find(int x,LIST L) { POSITION P; P=0; while(P!=L->size&&L->array[P]!=x) { P++; } return P; } void Delete(int x,LIST L) { int i; POSITION P; P=Find(x,L); if(P==L->size) printf(" Element not found in the list"); else { for(i=P;i<L->size;i++)
  • 6. L->array[i]=L->array[i+1]; L->size--; } } LIST Deletelist(LIST L) { MakeEmpty(L); free(L); L=NULL; return L; } void Display(LIST L) { int i; for(i=0;i<L->size;i++) printf(" %d",L->array[i]); } “Larray.c” File: #include"Larray.h" #include<stdlib.h> void main()
  • 7. { LIST L=NULL; POSITION P; int a,choice,ch,element; clrscr(); printf(" 1.Create 2.Insert 3.Delete 4.Display 5.MakeEmpty 6.Find 7.IsEmpty 8.IsFull 9.Deletelist 10.Exit "); A: printf(" Enter Ur Option:t"); scanf("%d",&choice); switch(choice) { case 1: if(L==NULL) L=Createlist(5); else printf(" List is already created"); break; case 2: if(L==NULL) printf(" List is not yet created"); else { printf(" Enter the Element to insert:t");
  • 8. scanf("%d",&element); if(L->size==0) Insert(element,L,0); else { printf(" where u want to insert?t1:Frontt2:Backt3:middlet::: "); scanf("%d",&ch); if(ch==1) Insert(element,L,0); else if(ch==2) Insert(element,L,L->size); else if(ch==3) { printf(" Where you want to insert:t"); scanf("%d",&a); P=Find(a,L); if(P<L->size) Insert(element,L,P); else printf(" Element is not in the list"); }
  • 9. else printf(" Ur choice is not available"); } } break; case 3: if(L==NULL) printf(" List is not yet created"); if(Isempty(L)) printf(" List is empty"); else { printf(" Enter the element to delete:t"); scanf("%d",&a); Delete(a,L); } break; case 4: if(L==NULL) printf(" List is not yet created"); else if(Isempty(L)) printf(" List is empty"); else {
  • 10. printf(" Elements present in the list are:"); Display(L); } break; case 5: if(L==NULL) printf(" List is not yet created "); else MakeEmpty(L); break; case 6: if(L==NULL) printf(" Not yet created"); else if(Isempty(L)) printf(" List is empty"); else { printf(" which element is to find:t"); scanf("%d",&a); P=Find(a,L); printf(" Element is at %dt[0 to 4 means present]t[5 means not present]",P); }
  • 11. break; case 7: if(L==NULL) printf(" Not yet created"); else if(Isempty(L)) printf(" List is empty"); else printf(" List is not empty"); break; case 8: if(L==NULL) printf(" Not yet created"); else if(Isfull(L)) printf(" List is FULL"); else printf(" List is not FULL"); break; case 9: if(L==NULL) printf(" Not yet created"); else { L=Deletelist(L);
  • 12. printf(" List is Deleted"); } break; case 10: exit (0); break; default: printf(" *******WRONG ENTRY*******"); break; } goto A; }