write a function in C to split a list into two sub-list using pointers?
363476
There's not enough information, what type of list, I don't think you mean an Enumerated List, and into what type of split, are you talking about linked lists, or something like indexing using trees to navigate or manage keys?
927748
You first define an array NodesList with index 0 as origin (C standard) containing all your nodes. The variable NodesNumber is the number of nodes. The key element is to define the operators S (for successor) and P (for predecessor) that will make the array behave as a circular list.\nS(NodesList[ i ]) = NodesList[ i + 1] if i < NodesNumber - 2\nand for the last node\nS(NodesList[ NodesNumber - 1 ]) = NodesList[ 0 ] \nSimilarly for P\nP(NodesList[ i ]) = NodesList[ i - 1] if i > 0\nand for the first node (origin)\nP(NodesList[ 0 ]) = NodesList[  NodesNumber - 1 ] \nThe algorithm has 2 parts\n// forward\nStartNode := NodesList[ NodesNumber - N  ]\nfor I := 1 to N\n  begin\n     StartNode := S(StartNode);\n     Node := StartNode;\n     Path := StartNode;\n     for J := 1 to N - 1\n        begin\n           Node := S(Node);\n           Add Node to Path \n        end \n      Record Path\n  end;\n// backward\nStartNode := NodesList[ N  ]\nfor I := 1 to N\n  begin\n     StartNode := P(StartNode);\n     Node := StartNode;\n     Path := StartNode;\n     for J := 1 to N - 1\n        begin\n           Node := P(Node);\n           Add Node to Path \n        end \n      Record Path\n  end;\nIn the second part the starting point is changed and S() are changed by P()
326706
var\nP : Array[0..10,11..20] of Pointer;
267921
You can turn these into proper C++ statements:\n\nread a, b\n\nlet max = a\n\nif max < b\n  let max = b\nendif\n\nprint max\n\nThis program assumes that a <> b.
1020339
You can use a number of different functions, but I would recommend looking at the STDIO ones:\n\nfopen()\nfclose()\nfprintf()\nfscanf()\netc...\n\nSo you want code something along the lines of:\n\n#include <stdio.h>\n...\nFILE * file = fopen("abc.txt");\nfprintf(file, "Hello %s&#92;n&#92;n", "Your Name Here");\nfclose(file);
295277
#include <iostream.h>\n#include <string.h>\n\nstruct String\n{\npublic:\nchar * Data;\nint Length;\n};\nString operator+(const String & s1,const String & s2)\n{\nchar * s3=new char [s1.Length+s2.Length];\nstrcpy(s3,s1.Data);\nstrcat(s3,s2.Data);\n\nString Out;\nOut.Data=s3;\nOut.Length=s1.Length+s2.Length;\nreturn Out;\n}\n\n//you can't directly overload char * because at least one operand of any overloaded operator must be of some user-defined type.\n\n//u can use strcat
244265
Think of a "doubly linked" list as a line of children holding hands on the playground.  (A circular list would have them all holding hands in a circle.)  All children would be holding the hand to a person on either side of them, with the exception of the two children at either end of the line have only one hand held.  (No hands held in the case of only one child.)\n\nNow, create a data structure that represents the child, and two pointers (which represent the hands of that child) that point to two other children.  (This can be a C structure or C++ class, your choice depending upon the assignment.)\n\nstruct Child\n{\n   Child* NextChild;\n   Child* PreviousChild;\n   char* MyName;\n};\n\nThe 'NextChild' and 'PreviousChild' members are 'pointers' to potential children (they represent the hands that are holding) that will be added to the list.  When you create one initial child, you will set these pointers to NULL, since the child is by himself.  The "MyName" member serves only to show the arbitrary data that is held by the list node.\n\nSo, the code for the initial child (in C) would be:\n\nChild* currentChild = (Child*)malloc(sizeof(Child));\n\ncurrentChild->NextChild = NULL;\ncurrentChild->PreviousChild = NULL;\n\nWe will assume that as we add new children, they will hold the hand of the starting child and add to the end of the list.\n\noldChild = currentChild;\ncurrentChild->NextChild = (Child*)(malloc(sizeof(Child)));\ncurrentChild = currentChild->NextChild;\n\ncurrentChild->NextChild = NULL;\ncurrentChild->PreviousChild = oldChild;\n\nThe "oldChild" is used to save the pointer to the current child, so that it could use it to set the "previous" child on the new child that is added to the line.  This is basically tell the new child that he is holding the hand of the child before him.  When the next child is added, his other hand will be filled with the new 'next child', then the next child will be hold the hand of the "previous" child, etc.\n\nNow, that will create the list for you.  To implement inserting items (i.e. moving children around the line, consider saving the "NextChild" and "PreviousChild" pointers, then setting them appropriately to disconnect them from existing children in the line and reconnecting them elsewhere.\n\nIf you use the "children holding hands" metaphor and treat their hands as the 'pointers', it will be easy to see how you can manipulate the doubly linked list.
115383
Another "answerer" correctly explained that you\ncould declare an array of pointers to a struct as:\n\n    struct foo *p[100];\n\nbut it might be useful for you to know about a\nutility that has been floating around the internet\nfor at least a couple of decades which tries to\n"translate" between a human readable syntax and\nC/C++ syntax for data declarations and casts.\nThe utility is "cdecl", and can easily be found\nwith google.\n\nAs an example, on this problem:\n\n$ cdecl\ncdecl> declare p as array 100 of pointer to struct foo\nstruct foo *p[100]\n\nWhat's interesting is that it can reverse the translation:\ncdecl\ncdecl> explain struct foo *p[100]\ndeclare p as array 100 of pointer to struct foo\n\nIt's not so exciting for something simple like this example,\nbut if you run across a declaration like:\n\nint *const*(**f)(int*,int*);\n\nyou can feed it to cdecl to get at least *some* idea of\nwhat it means:\n\ncdecl> explain int *const*(**f)(int*)\ndeclare f as pointer to pointer to function (pointer to int) returning pointer to const pointer to int\n\nSimilarly, it will generate "cast" syntax, ie:\n\ncdecl> cast p into pointer to pointer to function returning pointer to int\n(int *(**)())p
197553
I looked through it pretty carefully, and I believe\nit is correct.  I would, however, like to make a\ncouple of comments.\n\nFirst, this code makes no attempt at balancing the\ntrees, so you can easily end up with a linked list\nrather than a binary tree.  Consider if you created\nthe tree by passing in a set of sorted values.\n\nSecond, from the perspective of understanding the\nflow, it's a little harder when a routine has so\nmany distinct return points.  I'm not sure if it is\nbetter, but at least consider the following code\nwhich is semantically identical:\n\nTreeNode* InsertTree( TreeNode* tnPtr, const TreeItemType& item)\n{\n    // Inserting an item\n    if(tnPtr == NULL)\n        tnPtr = new TreeNode(item);\n\n    if(item < tnPtr->item_)\n        tnPtr->left_ = InsertTree(tnPtr->left_, item);\n    else if(item > tnPtr->item_)\n        tnPtr->right_ = InsertTree(tnPtr->right_, item);\n\n    return tnPtr;\n}
860477
Here is a program which first computes all the values and then, print it in the actual table manner. If value is 34, table for 1 to 10 will be printed first, then from 11 to 20, 21 to 30 and then from 31 to 34. \n\n#include <stdio.h>\n#include <conio.h>\n\nvoid main()\n{\n clrscr();\n int a[50][12];\n int n;\n printf("Enter the number till which you need tables ");\n scanf("%d",&n);\n for(int i= 1;i<=n;i++)\n  for(int j=1;j<=12;j++)\n   a[i][j] = i*j;\n\n for(int k=1;k<=n/10;k++)\n {\n\n  for(i = 1;i<=12;i++)\n  {\n   for(int j = (k-1)*10+1;j<=(k-1)*10+10;j++)\n    printf("%d&#92;t",a[j][i]);\n   //printf("&#92;n");\n  }\n  printf("&#92;n");\n  getch();\n }\n\n for(i = 1;i<=12;i++)\n  {\n   for(int j = (n/10)*10+1;j<=n;j++)\n    printf("%d&#92;t",a[j][i]);\n   printf("&#92;n");\n  }\n  printf("&#92;n");\n\n}
742648
#include<stdio.h>\n#include<conio.h>\nvoid main()\n{\nint n=5,i,j;\nclrscr();\nfor(i=1;i<=2*n-2;i++)\n{\nprintf(" ");\n}\nprintf("1&#92;n");\nfor(i=2;i<=n-1;i++)\n{\nfor(j = 1;j<=(n-i)*2;j++)\nprintf(" ");\nfor(j = i;j<=2*i-1;j++)\n{\nprintf("%d ",j);\n}\nfor(j = 2*i-2;j>=i;j--)\n{\nprintf("%d ",j);\n}\nprintf("&#92;n");\n}\nfor(i = n;i<=2*n-1;i++)\nprintf("%d ",i);\nfor(i = 2*n-2;i>=n;i--)\nprintf("%d ",i);\ngetch();\n}
52716
I hope you can understand the pseudocode, it's pretty loose.\n\nConstruct two arrays P and Q.\nLet P be empty, and Q contain the n numbers you want to permute.\nTo start, call the function PrintPermute below passing in the arrays P and Q.\n\nPrintPermute( P, Q)\n{\n  if Q is empty, print the values in P in order and return\n  else\n\n  for each value q in Q,\n  {\n       Create the strings P' and Q' where P' = P + q and Q' = Q - q\n       Call PrintPermute(P', Q')\n }\nreturn\n}
424535
your getting a user input for first and last name seperated by a space. use the strtok() function to extract the strings on either side of the space. then print it in the format you want.
1024904
Thats a recursive program for you.\nAnd I put an arbitrary limit of 9 there. You can change that for yourself.\n\n#include <stdio.h>\n\nvoid triangle(char ch, int count) {\n        int temp=0;\n        if (count==1) {\n                printf("%c&#92;n", ch);\n                return;\n        }\n        triangle(ch, count-1);\n        for(;temp<count;temp++) {\n                printf("%c", ch);\n        }\n        printf("&#92;n");\n}\n\nint main() {\n        char ch='*';\n        int count=0;\n        while((count<=0)||(count>=10)) {\n                printf("Enter the size of triangle (less than 10)&#92;n");\n                scanf("%d", &count);\n        }\n        triangle(ch, count);\n}
790827
main () {char *s, b[100]; while(s=gets(b)) printf (atoi(s)%2 ? "nope&#92;n" : "yep&#92;n");}
784164
sure you can use that syntax and it's correct this way:\nwrite(arraylist[x]);\nusualy this is used with a for clause\nfor i:=0 to n do\n write(arraylist[i]);\nbut if you put a pice of code when ur using this i can help you fix your errors.
1178151
If you know max.allowed width, use \nprintf( "%*.*s", width, width, arr[idx] )\n\nvoid printArray( char ** strings, int arr_sz, int columns, int min_width )\n{\nint rows = arr_sz/columns;\nfor( row = 0; row < rows, row++ )\nfor( col = 0; col < columns; col++ )\n{\n     int idx = columns*row+col;\n     if( idx >= arr_sz )\n           break;\n     printf( "%*.*s&#92;t", min_width, min_width , arr[idx] );\n}\nprintf( "&#92;n" );\n}