Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. singly linked list

singly linked list

Scheduled Pinned Locked Moved Managed C++/CLI
data-structurestutorial
7 Posts 2 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 13028254
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • U User 13028254

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      U 1 Reply Last reply
      0
      • L Lost User

        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.

        U Offline
        U Offline
        User 13028254
        wrote on last edited by
        #3

        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.h

        typedef int ElementType;
        #ifndef _List_H
        #define _List_H

        struct 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);
        #endif

        and 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

        L 1 Reply Last reply
        0
        • U User 13028254

          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.h

          typedef int ElementType;
          #ifndef _List_H
          #define _List_H

          struct 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);
          #endif

          and 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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          U 1 Reply Last reply
          0
          • L Lost User

            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.

            U Offline
            U Offline
            User 13028254
            wrote on last edited by
            #5

            thanks for your reply,but can you help me to show the sample code please..

            L 1 Reply Last reply
            0
            • U User 13028254

              thanks for your reply,but can you help me to show the sample code please..

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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.

              U 1 Reply Last reply
              0
              • L Lost User

                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.

                U Offline
                U Offline
                User 13028254
                wrote on last edited by
                #7

                Big thanks for your reply.. :) :) :) :)

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups