Thursday, July 30, 2009

Plz tell me a 'C'program depicting array implementation of linked list Abstract Data Type..?

The above program is included in Data Structures.It must include creation,insertion,deletion,search and display of nodes....If U cudn't help me with a full program..plz..tell me appropriate website for my question ...plz...

Plz tell me a 'C'program depicting array implementation of linked list Abstract Data Type..?
There's a full C program on the Wikipedia page for Linked List. I recommend that you study it and write your own. It's probably for a class assignment, so I strongly encourage you not to copy and paste code that you find on the web. Your instructor will respect you more if you do your own work.
Reply:int max_elm = 10;





/*element info's structure*/


struct tElmInfo {


int InfoA;


int InfoB;


/*another needed info goes here*/


}





/*List structure*/


struct tList {


int Head;


int Tail; /* if needed */


int count;


tElmInfo Elm[max_elm]; /*we assume that 0 elm won't be used*/


}








void main() {


/*List Var*/


tList List1;


createList(List1);


/*it depends your needs*/


}





void createList(tList *List){


/* we assume that if head and tail point 0, then the list is empty */


(*List).Head = 0;


(*List).Tail = 0;


}





int isEmpty(tList List) {


if ((List.Head == 0) %26amp;%26amp; (List.Tail == 0)) {


return 1;


} else {


return 0;


}


}





int isFull(tList List) {


if (List.count %26gt;= max_elm - 1) {


return 1;


} else {


return 0;


}


}





void insertLast(tList *List, tElmInfo X) {


if isFull((*List)) {


printf("List is FULL");


} else {


if isEmpty((*List)) {


(*List).Head = 1;


(*List).Tail = 1;


} else {


(*List).Tail++;


if ((*List).Tail %26gt;= max_elm) {


(*List).Tail = 1;


}


}


(*List).Elm[(*List).Tail] = X;


(*List).count++;


}


}


/* for other insert method (like insert first) just modify from code above (i'm sure you can do this) */





tElmInfo delFirst (tList *List) {


tElminfo tmpResult;


if (isEmpty((*List))) { /* actually you do this checking before call this function */


printf("List empty!");


} else {


tmpResult = (*List).element[(*List).Head];


(*List).count--;


if ((*List).Head == (*List).Tail) {


createList(List);


} else {


(*List).Head++;


}


if ((*List).Head %26gt;= max_elm) {


(*List).Head = 1;


}


return tmpResult;


}


}








I hope these will help. And I am sorry if there's ('re) mistake(s). There also a lot of other method out there. But the concept always be the same.
Reply:Below i have provided a link which may help u:


http://www.cprogramming.com/


This site contains tutorials %26amp; there are quizzes on C %26amp; C++.


Try it,i did too.

floral centerpieces

No comments:

Post a Comment