singly linked list
-
how to make a program in singly linked list that can divided two part,where the first linked list contain Element with an odd number element value and the second is even number. thank you
-
how to make a program in singly linked list that can divided two part,where the first linked list contain Element with an odd number element value and the second is even number. thank you
-
The C++ / CLI is for managed and mixed-mode C++ programming only - Managed C++/CLI Discussion Boards[^]. But before you do, please add some proper details as to what you have done, and where you are stuck.
thank you for your reply.. this is the code in klien.c
#include
#include
#include "list.h"int main(int argc, char *argv[]){
List L = NULL;
Position P = NULL;L = Construct(L); P = Header(L);
int i, n, *element;
printf("Entri element: ");
scanf("%d", &n);
element = (int*)malloc(n*sizeof(int));
for(i =0; i
this is the code in list.htypedef int ElementType;
#ifndef _List_H
#define _List_Hstruct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;List Construct(List L);
Position Header(List L);
void Insert(ElementType X, List L, Position P);
int IsLast(Position P, List L);
Position Advance(Position P);
Position getLargestElement(List L);
int IsEmpty(List L);
#endifand the last in list.c
#include #include #include "list.h"
struct Node{
ElementType Element;
Position Next;
};List Construct(List L){
L = malloc(sizeof(struct Node));
if(L==NULL)
printf("Memori Kosong dan Tidak Dapat Dialokasi");
L->Next = NULL;
return L;
}
Position Header(List L){
return L;
}void Insert(ElementType X, List L, Position P){
Position TmpCell = NULL;
TmpCell = malloc(sizeof(struct Node));
if(TmpCell == NULL) printf("Memori Kosong dan Tidak Dapat Dialokasi");
TmpCell->Element = X;
TmpCell->Next = P->Next;
P->Next = TmpCell;
}int IsLast(Position P, List L){
return P->Next == NULL;
}Position Advance(Position P){
return P->Next;
}int IsEmpty(List L){
return L->Next == NULL;
}Position getLargestElement (List L){
ElementType Largest;
Position P;
if(!IsEmpty(L)){
P = L->Next;
Largest = P->Element;
while(!IsLast(P, L)){
P = P->Next;
if(P->Element > Largest){
Largest = P->Element;
}} printf("element terbesar adalah: %d\\n",Largest); } else{ printf("tidak ada "); } return 0;
}
and my problem is i dont know how to make a splitlist function in my email before..
thank you -
thank you for your reply.. this is the code in klien.c
#include
#include
#include "list.h"int main(int argc, char *argv[]){
List L = NULL;
Position P = NULL;L = Construct(L); P = Header(L);
int i, n, *element;
printf("Entri element: ");
scanf("%d", &n);
element = (int*)malloc(n*sizeof(int));
for(i =0; i
this is the code in list.htypedef int ElementType;
#ifndef _List_H
#define _List_Hstruct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;List Construct(List L);
Position Header(List L);
void Insert(ElementType X, List L, Position P);
int IsLast(Position P, List L);
Position Advance(Position P);
Position getLargestElement(List L);
int IsEmpty(List L);
#endifand the last in list.c
#include #include #include "list.h"
struct Node{
ElementType Element;
Position Next;
};List Construct(List L){
L = malloc(sizeof(struct Node));
if(L==NULL)
printf("Memori Kosong dan Tidak Dapat Dialokasi");
L->Next = NULL;
return L;
}
Position Header(List L){
return L;
}void Insert(ElementType X, List L, Position P){
Position TmpCell = NULL;
TmpCell = malloc(sizeof(struct Node));
if(TmpCell == NULL) printf("Memori Kosong dan Tidak Dapat Dialokasi");
TmpCell->Element = X;
TmpCell->Next = P->Next;
P->Next = TmpCell;
}int IsLast(Position P, List L){
return P->Next == NULL;
}Position Advance(Position P){
return P->Next;
}int IsEmpty(List L){
return L->Next == NULL;
}Position getLargestElement (List L){
ElementType Largest;
Position P;
if(!IsEmpty(L)){
P = L->Next;
Largest = P->Element;
while(!IsLast(P, L)){
P = P->Next;
if(P->Element > Largest){
Largest = P->Element;
}} printf("element terbesar adalah: %d\\n",Largest); } else{ printf("tidak ada "); } return 0;
}
and my problem is i dont know how to make a splitlist function in my email before..
thank you -
You just need two new lists, one for odd numbers and one for even. Then for each value in the original list you add it to the appropriate new list.
thanks for your reply,but can you help me to show the sample code please..
-
thanks for your reply,but can you help me to show the sample code please..
-
You already have the code for a linked list, so all you need to do is to create two more the same as that one, and copy the elements from the original into the new ones. Odd elements to one list and even to the other.
Big thanks for your reply.. :) :) :) :)