In computer science, a list or sequence is an abstract data structure that implements an ordered collection of values, where the same value may occur more than once. An instance of a list is a computer representation of the mathematical concept of a finite sequence, that is, a tuple. Each instance of a value in the list is usually called an item, entry, or element of the list; if the same value occurs multiple times, each occurrence is considered a distinct item.
The name list is also used for several concrete data structures that can be used to implement abstract lists, especially linked lists.
The so-called static list structures allow only inspection and enumeration of the values. A mutable or dynamic list may allow items to be inserted, replaced, or deleted during the list's existence.
Many programming languages provide support for list data types, and have special syntax and semantics for lists and list operations. Often a list can be constructed by writing the items in sequence, separated by commas, semicolons, or spaces, within a pair of delimiters such as parentheses '()', brackets, '[]', braces '{}', or angle brackets '<>'. Some languages may allow list types to be indexed or sliced like array types. In object-oriented programming languages, lists are usually provided as instances of subclasses of a generic "list" class. List data types are often implemented using arrays or linked lists of some sort, but other data structures may be more appropriate for some applications. In some contexts, such as in Lisp programming, the term list may refer specifically to a linked list rather than an array.
----------------------------------------------------------------------------------------------
A C PROGRAM TO IMPLEMENT OPERATIONS IN LIST-ARRAY IMPLEMENTATION
COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2
SOURCE FILE SIZE :5 kb
EXE FILE SIZE :26 kb
NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE
---------------------------------------------------------------------------------------------
C PROGRAM SOURCE & EXE DOWNLOAD:
Click download button to download
DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.
----------------------------------------------------------------------------------------------
CODE:
#define MAX 10
int a[MAX],TOP=0,NO,NUM,i,A,B,C,V,ELE,POS,n;
int main()
{
int OPT;
char CH;
do
{
printf("\n LIST OPERATION USING LISTS");
printf("\n [1].LIST CREATION");
printf("\n [2].INSERTION-FIRST POSITION");
printf("\n [3].INSERTION-MIDDLE POSITION");
printf("\n [4].INSERTION-LAST POSITION");
printf("\n [5].DELETION -FIRST POSITION");
printf("\n [6].DELETION -MIDDLE POSITION");
printf("\n [7].DELETION -LAST POSITION");
printf("\n [8].ELEMENT SEARCH");
printf("\n [9].ELEMENT MODIFICATON");
printf("\n [10].TRAVERSAL");
printf("\n ENTER CHOICE:");
printf("\n CHOICE:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\n LIST CREATION:");
printf("\n CREATE FUNCTION INVOKED...");
CREATE();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 2:
printf("\n ELEMENT INSERTION-FIRST POSITION:");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSF();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 3:
printf("\n ELEMENT INSERTION-MIDDLE POSITION:");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSM();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 4:
printf("\n ELEMENT INSERTION-LAST POSITION::");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSL();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 5:
printf("\n ELEMENT DELETION-FIRST POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELF();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 6:
printf("\n ELEMENT DELETION-MIDDLE POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELM();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 7:
printf("\n ELEMENT DELETION-LAST POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELL();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 8:
printf("\n ELEMENT SEARCH:");
printf("\n SEARCH FUNCTION INVOKED...");
FIND();
break;
case 9:
printf("\n ELEMENT MODIFICATION:");
printf("\n ELEMENT MODIFICATION FUNCTION INVOKED...");
ELEMOD();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;
case 10:
printf("\n ELEMENT TRAVERSAL:");
printf("\n ELEMENT DISPLAY FUNCTION INVOKED...");
DISPLAY();
default:
printf("\nINVALID CHOICE");
}
printf("\n DO YOU WISH TO CONTINUE 1~2:");
scanf("%d",&CH);
}while(CH==1);
return 0;
}
//ARRAY CREATION
CREATE()
{
printf("\n ENTER THE TOTAL NUMBER OF ELEMENTS:");
scanf("%d",&NO);
for(i=0;i<=NO;i++)
{
scanf("%d",&NUM);
a[TOP]=NUM;
TOP++;
}
printf("\n CREATION IN PROGRESS...");
}
//INSERTING AN ELEMENT IN THE FIRST POSITION
INSF()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
for(i=TOP;i>=0;i--)
{
a[i]=a[i-1];
}
TOP++;
printf("\n ENTER THE ELEMENT TO BE INSERTED AT THE FIRST POSITION:");
scanf("%d",&a[0]);
}
}
//INSERTING AN ELEMENT IN THE MIDDLE POSITION
INSM()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
printf("\n ENTER THE POSITION TO INSERT THE ELEMENT:");
scanf("%d",&POS);
for(i=TOP;i>=POS;i--)
{
a[i]=a[i-1];
}
TOP++;
printf("\n ENTER THE ELEMENT TO BE INSERTED:");
scanf("%d",&A);
a[i]=A;
}
}
//INSERTING AN ELEMENT AT THE LAST POSITION
INSL()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
printf("\n ENTER THE ELEMENT TO BE INSERTED:");
scanf("%d",&B);
a[TOP]=B;
TOP++;
}
}
//DELETING AN ELEMENT AT THE FIRST POSITION
DELF()
{
if(TOP==0)
{
printf("\n THE LIST IS EMPTY");
}
else
{
printf("\n DELETION IN PROGRESS...");
n=a[0];
for(i=1;i<=TOP;i++)
{
a[i-1]=a[i];
}
TOP--;
a[TOP]=0;
}
}
//DELETING AN ELEMENT IN THE MIDDLE POSITION
DELM()
{
if(TOP==0)
{
printf("\n THE LIST IS EMPTY");
}
else
{
printf("\n DELETION IN PROGRESS...");
printf("\n ENTER THE POSITION TO DELETE THE ELEMENT:");
scanf("%d",&POS);
n=a[POS];
for(i=POS;i<=TOP;i++)
{
a[i-1]=a[i];
}
TOP--;
a[TOP]=0;
}
}
//DELETING AN ELEMENT AT THE LAST POSITION
DELL()
{
int n;
n=a[TOP];
if(TOP==0)
printf("\n THE LIST IS EMPTY");
else
{
printf("\n DELETION IN PROGRESS...");
a[TOP]=0;
TOP--;
}
}
//ELEMENT SEARCH
FIND()
{
printf("\n ENTER THE ELEMENT TO BE SEARCHED:");
scanf("%d",&ELE);
printf("\n SEARCH IN PROGRESS...");
for(i=0;i
if(a[i]==ELE)
{
printf("\n THE ELEMENT %d IS FOUND AT %d POSITION:",ELE,i+1);
}
else
{
printf("\n THE ELEMENT %d IS NOT FOUND AT %d POSITION:",ELE,i+1);
}
}
}
//ELEMENT MODIFICATION
ELEMOD()
{
printf("\nENTER THE POSITION OF THE ELEMENT TO BE MODIFIED:");
scanf("%d",&ELE);
B=a[i-1];
if(i<=TOP)
{
printf("\n THE ELEMENT IS:%d",B);
printf("\n ENTER THE NEW ELEMENT:");
scanf("%d",&C);
a[i-1]=C;
printf("\n MODIFICATION IN PROGRESS...");
printf("\n THE ELEMENT %d IS MODIFIED AS %d",B,C);
}
else
{
printf("\n ERROR \n ENTER WITHIN THE DEFINED RANGE");
}
}
// DISPLAY THE ELEMENTS IN THE ARRAY
DISPLAY()
{
for(i=0;i
printf("\n %d",a[i]);
}
}
----------------------------------------------------------------------------------------------
Your's friendly,
[MOHANRAM.G],
ADMIN...
0 comments:
Post a Comment