Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello guys
ok currently I'm strugling with a program (A simple data base) So I think I need to use linked list In my program to solve the problem ( Suggestion of a freind)
So I'm wodering how They can help me
And what's the utility of them

I'll just explain a bit about LinkedLists for u.
Basically they are similar to arrays, but:
They are NOT static in size and you can't index into them, only 'walk' the list (called traversing).here's some basic C code for a linked list.
(Only single links here, u can use double links)node = list->head ;#include <stdlib.h>
#include <iostream>using namespace std ;
struct int_node {
int data ;
struct int_node *next ;
} ;struct llist {
int count ;
struct int_node *head, *last ;
} ;typedef struct int_node IntNode ;
typedef struct llist LinkList ;LinkList * makeList() ;
void killList(LinkList *list) ;
void addValue(LinkList *list, int val) ;
void printList(LinkList *list) ;int main() {
LinkList *list = makeList() ;
int i ;for (i = 1 ; i <= 10 ; ++i)
addValue( list, i ) ;
printList( list ) ;
cout << list->count << endl ;killList( list ) ;
return 0 ;
}LinkList *makeList() {
LinkList *new_list = (LinkList*)malloc(sizeof(LinkList)) ;
new_list->count = 0 ;
new_list->head = NULL ;
new_list->last = NULL ;return new_list ;
}void killList(LinkList *list) {
if (list->count == 0)
free(list) ;
else {
IntNode *node, *tmp ;
for (node = list->head ; node != (IntNode*)NULL ;) {
tmp = node ;
node = node->next ;
free(tmp) ;
}
free(list) ;
}
}void addValue(LinkList *list, int val) {
IntNode *node = (IntNode*)malloc(sizeof(IntNode)) ;
node->data = val ;
node->next = NULL ;if ( list->count++ == 0 )
list->head = list->last = node ;
else {
list->last->next = node ;
list->last = node ;
}
}void printList(LinkList *list) {
IntNode *node ;
for (node = list->head ; node != (IntNode*)NULL ; node = node->next)
cout << node->data << " " ;
cout << endl ;
}There is HEAPS of info on this and other data structures on the Web so I won't explain this any further.

Sorry:
in line reading
node = list->head ;#include <stdlib.h>
ignode the node = list->head ; part, its a mistake!

![]() |
C ++
|
BUBBLE sort in array of S...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |